-
Notifications
You must be signed in to change notification settings - Fork 0
💝 A general purpose WithCommand option. #2
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
run: | ||
timeout: 5m | ||
|
||
linters: | ||
disable-all: false | ||
presets: | ||
- bugs | ||
- unused | ||
- complexity | ||
- format | ||
- performance | ||
- style | ||
enable: | ||
- gci | ||
disable: | ||
- paralleltest | ||
- nlreturn | ||
- exhaustivestruct | ||
- wsl | ||
- godox | ||
- scopelint | ||
- maligned | ||
- interfacer | ||
- golint | ||
- ireturn | ||
- varnamelen | ||
- exhaustruct | ||
- depguard | ||
|
||
issues: | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- wrapcheck | ||
|
||
linters-settings: | ||
gomoddirectives: | ||
# List of allowed `replace` directives. Default is empty. | ||
replace-allow-list: [] |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
module github.com/wavesoftware/go-commandline | ||
|
||
go 1.18 | ||
go 1.22.0 | ||
|
||
require ( | ||
github.com/spf13/cobra v1.5.0 | ||
github.com/spf13/cobra v1.8.1 | ||
github.com/wavesoftware/go-retcode v1.0.0 | ||
gotest.tools/v3 v3.3.0 | ||
gotest.tools/v3 v3.5.1 | ||
) | ||
|
||
require ( | ||
github.com/google/go-cmp v0.5.5 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
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,49 @@ | ||
package commandline | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Option is used to configure an App. | ||
type Option func(*App) | ||
|
||
// WithArgs creates an option which sets args. | ||
// Deprecated: use WithCommand instead. | ||
func WithArgs(args ...string) Option { | ||
return WithCommand(func(cmd *cobra.Command) { | ||
cmd.SetArgs(args) | ||
}) | ||
} | ||
|
||
// WithInput creates an option witch sets os.Stdin. | ||
// Deprecated: use WithCommand instead. | ||
func WithInput(in io.Reader) Option { | ||
return WithCommand(func(cmd *cobra.Command) { | ||
cmd.SetIn(in) | ||
}) | ||
} | ||
|
||
// WithOutput creates an option witch sets os.Stdout and os.Stderr. | ||
// Deprecated: use WithCommand instead. | ||
func WithOutput(out io.Writer) Option { | ||
return WithCommand(func(cmd *cobra.Command) { | ||
cmd.SetOut(out) | ||
cmd.SetErr(out) | ||
}) | ||
} | ||
|
||
// WithCommand will allow one to change the cobra.Command. | ||
func WithCommand(fn func(cmd *cobra.Command)) Option { | ||
return func(app *App) { | ||
fn(app.root) | ||
} | ||
} | ||
|
||
// WithExit creates an option which sets the exit function. | ||
func WithExit(fn func(code int)) Option { | ||
return func(app *App) { | ||
app.Exit = fn | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.