Skip to content

Commit

Permalink
Update CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
Iurii Bogdanov committed Jan 11, 2024
1 parent ea495cd commit 237e8a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ bin/base64 encode "hello WoRld 123 ~~~"
Encode with variant:
```terminal
bin/base64 encode_with_variant [CONTENT] [VARIANT]
bin/base64 encode_with_variant "hello WoRld 123 ~~~" 1
bin/base64 encode_with_variant "hello WoRld 123 ~~~" original
# Output: aGVsbG8gV29SbGQgMTIzIH5+fg==
bin/base64 encode_with_variant "hello WoRld 123 ~~~" 2
bin/base64 encode_with_variant "hello WoRld 123 ~~~" original_no_padding
# Output: aGVsbG8gV29SbGQgMTIzIH5+fg
bin/base64 encode_with_variant "hello WoRld 123 ~~~" 4
bin/base64 encode_with_variant "hello WoRld 123 ~~~" urlsafe
# Output: aGVsbG8gV29SbGQgMTIzIH5-fg==
bin/base64 encode_with_variant "hello WoRld 123 ~~~" 8
bin/base64 encode_with_variant "hello WoRld 123 ~~~" urlsafe_no_padding
# Output: aGVsbG8gV29SbGQgMTIzIH5-fg
```

Expand All @@ -98,13 +98,13 @@ bin/base64 decode aGVsbG8gV29SbGQgMTIzIH5+fg==
Decode with variant:
```terminal
bin/base64 decode_with_variant [CONTENT] [VARIANT]
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5+fg== 1
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5+fg== original
# Output: hello WoRld 123 ~~~
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5+fg 2
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5+fg original_no_padding
# Output: hello WoRld 123 ~~~
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5-fg== 4
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5-fg== urlsafe
# Output: hello WoRld 123 ~~~
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5-fg 8
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5-fg urlsafe_no_padding
# Output: hello WoRld 123 ~~~
```

Expand Down
9 changes: 8 additions & 1 deletion bin/base64
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ $content = $argv[2] ?? null;
$variant = $argv[3] ?? null;

if (null !== $variant) {
$variant = (int) $variant;
$variant = (string) $variant;
$variant = match ($variant) {
'original' => Base64::BASE64_VARIANT_ORIGINAL,
'original_no_padding' => Base64::BASE64_VARIANT_ORIGINAL_NO_PADDING,
'urlsafe' => Base64::BASE64_VARIANT_URLSAFE,
'urlsafe_no_padding' => Base64::BASE64_VARIANT_URLSAFE_NO_PADDING,
default => 0,
};
}

try {
Expand Down

0 comments on commit 237e8a3

Please sign in to comment.