-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli module based on github.com/urfave/cli (#182)
- Loading branch information
Showing
21 changed files
with
1,290 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env risor -- | ||
|
||
from cli import app, command, flag | ||
|
||
// Usage: | ||
// ./examples/scripts/encode_cli.risor base64 hello | ||
// aGVsbG8= | ||
// | ||
// ./examples/scripts/encode_cli.risor hex hello | ||
// 68656c6c6f | ||
// | ||
// ./examples/scripts/encode_cli.risor -h | ||
// <help text shown> | ||
// | ||
// ./examples/scripts/encode_cli.risor list-codecs -v | ||
// Codec 1: base64 | ||
// Codec 2: hex | ||
|
||
// Create a new CLI app named "encode" | ||
app({ | ||
name: "encode", | ||
help_name: "encode", | ||
description: "Encode input text using various codecs", | ||
// Register three commands, named "base64", "hex", and "list-codecs" | ||
commands: [ | ||
command({ | ||
name: "base64", | ||
action: func(ctx) { | ||
// Print the base64 encoded text | ||
for _, text := range ctx.args() { | ||
print(encode(text, "base64")) | ||
} | ||
} | ||
}), | ||
command({ | ||
name: "hex", | ||
action: func(ctx) { | ||
// Print the hex encoded text | ||
for _, text := range ctx.args() { | ||
print(encode(text, "hex")) | ||
} | ||
} | ||
}), | ||
command({ | ||
name: "list-codecs", | ||
flags: [ | ||
flag({ | ||
name: "verbose", | ||
aliases: ["v"], | ||
usage: "Print verbose output", | ||
env_vars: ["VERBOSE"], | ||
value: false, | ||
}), | ||
], | ||
action: func(ctx) { | ||
codecs := ["base64", "hex"] | ||
if ctx.bool("verbose") { | ||
// Print all available codecs | ||
for i, codec := range codecs { | ||
print('Codec {i+1}: {codec}') | ||
} | ||
} else { | ||
// Print only the codec names | ||
for _, codec := range codecs { | ||
print(codec) | ||
} | ||
} | ||
} | ||
}), | ||
] | ||
}).run() // Run the app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.