-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💝 A general purpose WithCommand option. (#2)
A general purpose WithCommand option.
- Loading branch information
Showing
9 changed files
with
127 additions
and
54 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
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 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 |
---|---|---|
@@ -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 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,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 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