Skip to content

Commit

Permalink
Add '--quiet' Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jenslauterbach committed Mar 13, 2021
1 parent ccbec57 commit e2e3d8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ See chapter [Flags and Arguments](#flags-and-arguments) for an overview of all a
|--max-retries|Maximum number of retries (default: 3)|
|--no-input|Do not require any input|
|--profile|AWS profile to use|
|--quiet|Disable all output (except for required input)|
|--region|AWS region of DynamoDB table (overwrite default region)|
|--version|Show version number and quit|

Expand Down
12 changes: 12 additions & 0 deletions cmd/ddbt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Options:
--max-retries Maximum number of retries (default: 3)
--no-input Do not require any input
--profile AWS profile to use
--quiet Disable all output (except for required input)
--region AWS region of DynamoDB table (overwrite default region)
--version Show version number and quit
`
Expand Down Expand Up @@ -103,6 +104,10 @@ func run(args []string) error {
pterm.EnableDebugMessages()
}

if parsedArguments.quiet {
pterm.DisableOutput()
}

conf, err := newConfig(parsedArguments)
if err != nil {
return err
Expand Down Expand Up @@ -132,7 +137,11 @@ func run(args []string) error {
}

func askForConfirmation(reader io.RuneReader, tableInfo *dynamodb.DescribeTableOutput) bool {
// Explicitly enable output before showing the question. The user might have used the --quiet flag. If that is the
// case the output would not be enabled, the question would not be shown.
pterm.EnableOutput()
pterm.Warning.Printf("Do you really want to delete approximately %d items from table %s? [Y/n] ", tableInfo.Table.ItemCount, *tableInfo.Table.TableArn)
pterm.DisableOutput()

input, _, err := reader.ReadRune()
if err != nil {
Expand Down Expand Up @@ -178,6 +187,7 @@ type arguments struct {
version bool
dryRun bool
noInput bool
quiet bool
}

func parseArguments(flags *flag.FlagSet, args []string) (arguments, error) {
Expand All @@ -190,6 +200,7 @@ func parseArguments(flags *flag.FlagSet, args []string) (arguments, error) {
version := flags.Bool("version", false, "show version")
dry := flags.Bool("dry-run", false, "run command without actually deleting items")
noInput := flags.Bool("no-input", false, "Do not require any input")
quiet := flags.Bool("quiet", false, "Disable all output (except for required input)")

err := flags.Parse(args)
if err != nil {
Expand Down Expand Up @@ -218,6 +229,7 @@ func parseArguments(flags *flag.FlagSet, args []string) (arguments, error) {
version: *version,
dryRun: *dry,
noInput: *noInput,
quiet: *quiet,
}, nil
}

Expand Down

0 comments on commit e2e3d8f

Please sign in to comment.