Skip to content

Commit

Permalink
refactor: optimize some flags description
Browse files Browse the repository at this point in the history
  • Loading branch information
windvalley committed Jan 16, 2024
1 parent 8989e59 commit d1ed85f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.15.1]

### Changed

- Optimize config template and config file.
- Optimize pubkeys authentication.
- Optimize some flags description.

## [1.15.0]

### Added
Expand Down
70 changes: 35 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,41 +144,41 @@ Available Commands:
completion Generate the autocompletion script for the specified shell
Flags:
-u, --auth.user string login user (default $USER)
-p, --auth.password string password of login user
-k, --auth.ask-pass ask for the password of login user
-a, --auth.pass-file string file that holds the password of login user
-I, --auth.identity-files strings identity files (default ~/.ssh/id_rsa)
-K, --auth.passphrase string passphrase of the identity files
-V, --auth.vault-pass-file string text file or executable file that holds the vault password
for encryption and decryption
-i, --hosts.inventory string file that holds the target hosts
-P, --hosts.port int port of the target hosts (default 22)
-l, --hosts.list outputs a list of target hosts, and does not do anything else
-s, --run.sudo use sudo to execute commands/script or fetch files/dirs
-U, --run.as-user string run via sudo as this user (default "root")
-L, --run.lang string specify i18n while executing command
(e.g. zh_CN.UTF-8|en_US.UTF-8)
-c, --run.concurrency int number of concurrent connections (default 1)
-B, --run.command-blacklist strings commands that are prohibited from execution on target hosts
(default: rm,reboot,halt,shutdown,init,mkfs,mkfs.*,umount,dd)
-o, --output.file string file to which messages are output
-j, --output.json output messages in json format
-C, --output.condense condense output and disable color
-q, --output.quiet do not output messages to screen
-v, --output.verbose show debug messages
-X, --proxy.server string proxy server address
--proxy.port int proxy server port (default 22)
--proxy.user string login user for proxy (default same as 'auth.user')
--proxy.password string password for proxy (default same as 'auth.password')
--proxy.identity-files strings identity files for proxy (default same as 'auth.identity-files')
--proxy.passphrase string passphrase of the identity files for proxy
(default same as 'auth.passphrase')
-t, --timeout.command int timeout seconds for handling each target host
--timeout.task int timeout seconds for the entire gossh task
--timeout.conn int timeout seconds for connecting each target host (default 10)
--config string config file (default {$PWD,$HOME}/.gossh.yaml)
-h, --help help for gossh
-u, --auth.user string login user (default $USER)
-p, --auth.password string password of login user
-k, --auth.ask-pass ask for the password of login user
-a, --auth.pass-file string file that holds the password of login user
-I, --auth.identity-files strings identity files (default [~/.ssh/id_rsa])
-K, --auth.passphrase string passphrase of the identity files
-V, --auth.vault-pass-file string text file or executable file that holds the vault password
for encryption and decryption
-i, --hosts.inventory string file that holds the target hosts
-P, --hosts.port int port of the target hosts (default 22)
-l, --hosts.list outputs a list of target hosts, and does not do anything else
-s, --run.sudo use sudo to execute commands/script or fetch files/dirs
-U, --run.as-user string run via sudo as this user (default "root")
-L, --run.lang string specify i18n while executing command
(e.g. zh_CN.UTF-8|en_US.UTF-8)
-c, --run.concurrency int number of concurrent connections (default 1)
-B, --run.command-blacklist strings commands that are prohibited from execution on target hosts
(default: [rm,reboot,halt,shutdown,init,mkfs,mkfs.*,umount,dd])
-o, --output.file string file to which messages are output
-j, --output.json output messages in json format
-C, --output.condense condense output and disable color
-q, --output.quiet do not output messages to screen
-v, --output.verbose show debug messages
-X, --proxy.server string proxy server address
--proxy.port int proxy server port (default 22)
--proxy.user string login user for proxy (default same as 'auth.user')
--proxy.password string password for proxy (default same as 'auth.password')
--proxy.identity-files strings identity files for proxy (default same as 'auth.identity-files')
--proxy.passphrase string passphrase of the identity files for proxy
(default same as 'auth.passphrase')
-t, --timeout.command int timeout seconds for handling each target host
--timeout.task int timeout seconds for the entire gossh task
--timeout.conn int timeout seconds for connecting each target host (default 10)
--config string config file (default {$PWD,$HOME}/.gossh.yaml)
-h, --help help for gossh
Use "gossh [command] --help" for more information about a command.
```
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/configflags/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ type Auth struct {
VaultPassFile string `json:"vault-pass-file" mapstructure:"vault-pass-file"`
}

// NewAuth ...
// NewAuth config.
func NewAuth() *Auth {
return &Auth{
User: "",
Password: "",
AskPass: false,
PassFile: "",
IdentityFiles: []string{},
IdentityFiles: []string{"~/.ssh/id_rsa"},
Passphrase: "",
VaultPassFile: "",
}
}

// AddFlagsTo pflagSet.
func (a *Auth) AddFlagsTo(fs *pflag.FlagSet) {
fs.StringVarP(&a.User, flagAuthUser, "u", "", "login user (default $USER)")
fs.StringVarP(&a.User, flagAuthUser, "u", a.User, "login user (default $USER)")
fs.StringVarP(&a.Password, flagAuthPassword, "p", a.Password, "password of login user")
fs.BoolVarP(&a.AskPass, flagAuthAskPass, "k", a.AskPass, "ask for the password of login user")
fs.StringVarP(&a.PassFile, flagAuthPassFile, "a", a.PassFile,
`file that holds the password of login user`)
fs.StringSliceVarP(&a.IdentityFiles, flagAuthIdentityFiles, "I", nil,
"identity files (default ~/.ssh/id_rsa)")
fs.StringSliceVarP(&a.IdentityFiles, flagAuthIdentityFiles, "I", a.IdentityFiles,
"identity files")
fs.StringVarP(&a.Passphrase, flagAuthPassphrase, "K", a.Passphrase,
"passphrase of the identity files")
fs.StringVarP(&a.VaultPassFile, flagAuthVaultPassFile, "V", a.VaultPassFile,
Expand Down
7 changes: 1 addition & 6 deletions internal/pkg/configflags/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const (
flagRunCommandBlacklist = "run.command-blacklist"
)

// Run ...
type Run struct {
Sudo bool `json:"sudo" mapstructure:"sudo"`
AsUser string `json:"as-user" mapstructure:"as-user"`
Expand All @@ -46,7 +45,6 @@ type Run struct {
CommandBlacklist []string `json:"command-blacklist" mapstructure:"command-blacklist"`
}

// NewRun ...
func NewRun() *Run {
return &Run{
Sudo: false,
Expand All @@ -55,7 +53,6 @@ func NewRun() *Run {
}
}

// AddFlagsTo ...
func (r *Run) AddFlagsTo(flags *pflag.FlagSet) {
flags.BoolVarP(&r.Sudo, flagRunSudo, "s", r.Sudo, "use sudo to execute commands/script or fetch files/dirs")
flags.StringVarP(&r.AsUser, flagRunAsUser, "U", r.AsUser, "run via sudo as this user")
Expand All @@ -75,11 +72,10 @@ func (r *Run) AddFlagsTo(flags *pflag.FlagSet) {
"B",
r.CommandBlacklist,
`commands that are prohibited from execution on target hosts
(default: rm,reboot,halt,shutdown,init,mkfs,mkfs.*,umount,dd)`,
(default: [rm,reboot,halt,shutdown,init,mkfs,mkfs.*,umount,dd])`,
)
}

// Complete ...
func (r *Run) Complete() error {
newSlice := make([]string, 0)
for _, s := range r.CommandBlacklist {
Expand All @@ -94,7 +90,6 @@ func (r *Run) Complete() error {
return nil
}

// Validate ...
func (r *Run) Validate() (errs []error) {
if r.Concurrency < 1 {
errs = append(errs, fmt.Errorf(
Expand Down

0 comments on commit d1ed85f

Please sign in to comment.