1
0
mirror of https://github.com/smallstep/cli.git synced 2025-08-07 16:02:54 +03:00

Add --quiet option to step ssh check-host

This commit is contained in:
Carl Tashian
2021-04-13 14:17:17 -07:00
parent 5038f8f14a
commit 039e718a74

View File

@@ -25,11 +25,11 @@ func checkHostCommand() cli.Command {
Usage: "checks if a certificate has been issued for a host", Usage: "checks if a certificate has been issued for a host",
UsageText: `**step ssh check-host** <hostname> UsageText: `**step ssh check-host** <hostname>
[**--ca-url**=<uri>] [**--root**=<file>] [**--ca-url**=<uri>] [**--root**=<file>]
[**--offline**] [**--ca-config**=<path>]`, [**--offline**] [**--ca-config**=<path>] [**--quiet**]`,
Description: `**step ssh check-host** checks if a certificate has been issued for a host. Description: `**step ssh check-host** checks if a certificate has been issued for a host.
This command returns a zero exit status then the server exists, it will return 1 This command prints "true" and returns a zero exit status if the host has a certificate.
otherwise. Otherwise, it prints "false" and returns 1.
## POSITIONAL ARGUMENTS ## POSITIONAL ARGUMENTS
@@ -47,11 +47,17 @@ $ step ssh check-host internal.smallstep.com
flags.Root, flags.Root,
flags.Offline, flags.Offline,
flags.CaConfig, flags.CaConfig,
cli.BoolFlag{
Name: "quiet",
Usage: `Silently return an exit code.`,
},
}, },
} }
} }
func checkHostAction(ctx *cli.Context) error { func checkHostAction(ctx *cli.Context) error {
isQuiet := ctx.Bool("quiet")
if err := errs.NumberOfArguments(ctx, 1); err != nil { if err := errs.NumberOfArguments(ctx, 1); err != nil {
return err return err
} }
@@ -96,7 +102,9 @@ func checkHostAction(ctx *cli.Context) error {
"error checking ssh host eligibility") "error checking ssh host eligibility")
} }
fmt.Println(resp.Exists) if !isQuiet {
fmt.Println(resp.Exists)
}
if !resp.Exists { if !resp.Exists {
os.Exit(1) os.Exit(1)
} }