-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cli): enhance CLI flexibility and fix option precedence #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b41606b
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] ae02043
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] f516b0d
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] fba26e1
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] 64435b9
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] e1193c7
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] e136f64
feat(cli): enhance CLI flexibility and fix option precedence
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,79 @@ | ||
| <!-- Code generated by github.com/arran4/go-subcommand/cmd/gosubc. DO NOT EDIT. --> | ||
| All code under /cmd is generated code, do not place files here. | ||
|
|
||
| # Go Subcommand Information | ||
|
|
||
| Go Subcommand (`gosubc`) generates subcommand code for command-line interfaces (CLIs) in Go from source code comments. | ||
|
|
||
| ## Key Features | ||
|
|
||
| - **Convention over Configuration:** Define your CLI structure with simple, intuitive code comments. | ||
| - **Zero Dependencies:** The generated code is self-contained and doesn't require any external libraries. | ||
| - **Automatic Code Generation:** `gosubc` parses your Go files and generates a complete, ready-to-use CLI. | ||
|
|
||
| ## Installation | ||
|
|
||
| `gosubc` is a standalone tool and should not be added as a dependency in your `go.mod`. Install it using: | ||
|
|
||
| ```bash | ||
| go install github.com/arran4/go-subcommand/cmd/gosubc@latest | ||
| ``` | ||
|
|
||
| ## How it works | ||
|
|
||
| 1. **Define Your Commands**: Create a Go file and define a function that will serve as your command. Add a comment above the function. | ||
| 2. **Generate**: Run `gosubc generate` (or via `go generate`). | ||
| 3. **Result**: `gosubc` creates a `cmd/<app-name>` directory containing the generated CLI code. | ||
|
|
||
| ## Comment Syntax | ||
|
|
||
| ### Command Definition | ||
|
|
||
| ```go | ||
| // FuncName is a subcommand 'root-cmd parent child' | ||
| func FuncName() {} | ||
| ``` | ||
|
|
||
| ### Flags | ||
|
|
||
| Use a `Flags:` block or inline comments. Adhere to Go formatting. | ||
|
|
||
| ```go | ||
| // FuncName is a subcommand 'root-cmd parent child' | ||
| // | ||
| // Flags: | ||
| // | ||
| // username: --username -u (default: "guest") The user to greet | ||
| // count: --count -c (default: 1) Number of times | ||
| func FuncName(username string, count int) {} | ||
| ``` | ||
|
|
||
| ### Positional Arguments | ||
|
|
||
| Map positional arguments using `@N`. | ||
|
|
||
| ```go | ||
| // Greet is a subcommand 'app greet' | ||
| // | ||
| // Flags: | ||
| // | ||
| // name: @1 The name to greet | ||
| func Greet(name string) {} | ||
| ``` | ||
|
|
||
| ### Variadic Arguments | ||
|
|
||
| Map remaining arguments using `...`. | ||
|
|
||
| ```go | ||
| // Process is a subcommand 'app process' | ||
| // | ||
| // Flags: | ||
| // | ||
| // files: ... List of files | ||
| func Process(files ...string) {} | ||
| ``` | ||
|
|
||
| ## Important Note | ||
|
|
||
| Do not edit files in this directory directly if you can avoid it. They are overwritten on every generation. Modify the source code comments instead. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jules the documentation needs to be expanded a lot about how to use these new commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've expanded the
README.mdsection on CLI usage, including examples of using standard commands with options (strings2 kebab --first-upper,strings2 snake --screaming) and a comprehensive list of all the newly exposed flags.