Skip to content

Commit

Permalink
refactor: optimize usage examples for subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
windvalley committed Jan 5, 2024
1 parent 4bf61f1 commit 2c5a417
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ Flags:
--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)
--timeout.command int timeout seconds for handling each target host
--config string config file (default {$PWD,$HOME}/.gossh.yaml)
-h, --help help for gossh
Expand Down
2 changes: 1 addition & 1 deletion docs/vault.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Confirm plaintext:
GOSSH-AES256:349a1220bc8adbb6b784624e8f4e913b24cf0836c45b73e9ab16c66cec7c3adf
```

### demo3
#### demo3

```sh
$ gossh vault encrypt "the-password" -V ./vault-pass-file
Expand Down
7 changes: 5 additions & 2 deletions internal/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import (
var shellCommand string

const commandCmdExamples = `
# Execute command 'uptime' on target hosts.
Execute command 'uptime' on target hosts.
$ gossh command host1 host2 -e "uptime" -u zhangsan -k
# Use sudo as root to execute command on target hosts.
Use sudo as root to execute command on target hosts.
$ gossh command host[1-2] -e "uptime" -u zhangsan -s
Use sudo as other user 'mysql' to execute command on target hosts.
$ gossh command host[1-2] -e "uptime" -u zhangsan -s -U mysql
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/command.md`

// commandCmd represents the 'command' command
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ Generate gossh configuration file.
Default configuration file path: $PWD/.gossh.yaml and $HOME/.gossh.yaml,
and $PWD/.gossh.yaml has higher priority than $HOME/.gossh.yaml`,
Example: `
# Generate default configuration content to screen.
Generate default configuration content to screen.
$ gossh config
# Generate default configuration file.
Generate default configuration file.
$ gossh config > ~/.gossh.yaml
# Generate configuration file with customized field values by specifying some global flags.
Generate configuration file with customized field values by specifying some global flags.
$ gossh config -u zhangsan -c 100 -j --timeout.command 20 > ./.gossh.yaml`,
Run: func(cmd *cobra.Command, args []string) {
config := configflags.Config
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ var scriptCmd = &cobra.Command{
Long: `
Execute a local shell script on target hosts.`,
Example: `
# Execute foo.sh on target hosts.
Execute foo.sh on target hosts.
$ gossh script host[1-3] -e foo.sh -k
# Remove the copied 'foo.sh' on the target hosts after execution.
Remove the copied 'foo.sh' on the target hosts after execution.
$ gossh script host[1-3] -i hosts.txt -e foo.sh -k -r
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/script.md`,
Expand Down
8 changes: 5 additions & 3 deletions internal/cmd/vault/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ var decryptCmd = &cobra.Command{
Long: `
Decrypt content encrypted by vault.`,
Example: `
# Decrypt cipher text by asking for vault password.
Decrypt cipher text by asking for vault password.
$ gossh vault decrypt GOSSH-AES256:a5c1b3c0cdad4669f84
# Decrypt cipher text by vault password file or script.
$ gossh vault decrypt GOSSH-AES256:a5c1b3c0cdad4669f84 -V /path/vault-password-file-or-script`,
Decrypt cipher text by vault password file or script.
$ gossh vault decrypt GOSSH-AES256:a5c1b3c0cdad4669f84 -V /path/vault-password-file-or-script
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/vault.md`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
util.CobraCheckErrWithHelp(cmd, "requires one arg to represent the vault encrypted content")
Expand Down
12 changes: 7 additions & 5 deletions internal/cmd/vault/decrypt_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ var decryptFileCmd = &cobra.Command{
Long: `
Decrypt vault encrypted file.`,
Example: `
# Decrypt a vault encrypted file by asking for vault password.
Decrypt a vault encrypted file by asking for vault password.
$ gossh vault decrypt-file /path/auth.txt
# Decrypt a vault encrypted file by vault password file or script.
Decrypt a vault encrypted file by vault password file or script.
$ gossh vault decrypt-file /path/auth.txt -V /path/vault-password-file-or-script
# Output decrypted content to another file.
Output decrypted content to another file.
$ gossh vault decrypt-file /path/auth.txt -O /path/plaintxt.txt
# Output decrypted content to screen.
$ gossh vault decrypt-file /path/auth.txt -O -`,
Output decrypted content to screen.
$ gossh vault decrypt-file /path/auth.txt -O -
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/vault.md`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
util.CobraCheckErrWithHelp(cmd, "requires one arg to represent the vault encrypted file")
Expand Down
10 changes: 6 additions & 4 deletions internal/cmd/vault/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ var encryptCmd = &cobra.Command{
Long: `
Encrypt sensitive content.`,
Example: `
# Encrypt plaintext by asking for vault password.
Encrypt plaintext by asking for vault password.
$ gossh vault encrypt "your-sensitive-plaintext"
# Encrypt plaintext by vault password file or script.
Encrypt plaintext by vault password file or script.
$ gossh vault encrypt "your-sensitive-plaintext" -V /path/vault-password-file-or-script
# Encrypt plaintext from terminal prompt.
$ gossh vault encrypt -V /path/vault-password-file`,
Encrypt plaintext from terminal prompt.
$ gossh vault encrypt -V /path/vault-password-file
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/vault.md`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
util.CobraCheckErrWithHelp(cmd, "to many args, only need one")
Expand Down
12 changes: 7 additions & 5 deletions internal/cmd/vault/encrypt_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ var encryptFileCmd = &cobra.Command{
Long: `
Encrypt a file.`,
Example: `
# Encrypt a file by asking for vault password.
Encrypt a file by asking for vault password.
$ gossh vault encrypt-file /path/auth.txt
# Encrypt a file by vault password file or script.
Encrypt a file by vault password file or script.
$ gossh vault encrypt-file /path/auth.txt -V /path/vault-password-file-or-script
# Output encrypted content to another file.
Output encrypted content to another file.
$ gossh vault encrypt-file /path/auth.txt -O /path/encryption.txt
# Output encrypted content to screen.
$ gossh vault encrypt-file /path/auth.txt -O -`,
Output encrypted content to screen.
$ gossh vault encrypt-file /path/auth.txt -O -
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/vault.md`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
util.CobraCheckErrWithHelp(cmd, "requires one arg to represent a file to be encrypted")
Expand Down
8 changes: 5 additions & 3 deletions internal/cmd/vault/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ var viewCmd = &cobra.Command{
Long: `
View vault encrypted file.`,
Example: `
# View a vault encrypted file by asking for vault password.
View a vault encrypted file by asking for vault password.
$ gossh vault view /path/auth.txt
# View a vault encrypted file by vault password file or script.
$ gossh vault view /path/auth.txt -V /path/vault-password-file-or-script`,
View a vault encrypted file by vault password file or script.
$ gossh vault view /path/auth.txt -V /path/vault-password-file-or-script
Find more examples at: https://github.com/windvalley/gossh/blob/main/docs/vault.md`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
util.CobraCheckErrWithHelp(cmd, "requires one arg to represent the vault encrypted file")
Expand Down

0 comments on commit 2c5a417

Please sign in to comment.