Skip to content
Merged

dev #69

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,3 @@ The library is in a pre-release candidate status:

Please open a PR or an issue if you wish to bring enhancements to it.
Other contributions, as well as bug fixes and reviews are also welcome.


## Possible Improvements

The following is a currently moving list of possible enhancements to be made in order to reach `v1.0`:
- [ ] Ensure to the best extent possible a thread-safe access to the command API.
- [ ] Clearer integration/alignment of the various I/O references between raw readline and commands.
- [ ] Clearer and sane model for asynchronous control/cancel of commands (with OnKillRun in cobra)
- [ ] Test suite for most important or risky code paths.
37 changes: 0 additions & 37 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package console

import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

const (
Expand Down Expand Up @@ -74,39 +73,3 @@ next:

c.filters = updated
}

// resetFlagsDefaults resets all flags to their default values.
//
// Slice flags accumulate per execution (and do not reset),
//
// so we must reset them manually.
//
// Example:
//
// Given cmd.Flags().StringSlice("comment", nil, "")
// If you run a command with --comment "a" --comment "b" you will get
// the expected [a, b] slice.
//
// If you run a command again with no --comment flags, you will get
// [a, b] again instead of an empty slice.
//
// If you run the command again with --comment "c" --comment "d" flags,
// you will get [a, b, c, d] instead of just [c, d].
func resetFlagsDefaults(target *cobra.Command) {
target.Flags().VisitAll(func(flag *pflag.Flag) {
flag.Changed = false
switch value := flag.Value.(type) {
case pflag.SliceValue:
var res []string

if len(flag.DefValue) > 0 && flag.DefValue != "[]" {
res = append(res, flag.DefValue)
}

value.Replace(res)

default:
flag.Value.Set(flag.DefValue)
}
})
}
Loading
Loading