Skip to content

Commit

Permalink
restraint cmd.Set and cmd.Store (=cmdr.CmdStore()).
Browse files Browse the repository at this point in the history
	// Set returns the application Store [store.Store]
	Set() store.Store
	// Store returns the commands subset of the application Store.
	Store() store.Store
  • Loading branch information
hedzr committed Oct 21, 2024
1 parent ce86932 commit cefb7ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cli/baseopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func (c *BaseOpt) OwnerOrParent() BacktraceableMin { return c.owner }
func (c *BaseOpt) OwnerIsNil() bool { return c.owner == nil }
func (c *BaseOpt) OwnerIsNotNil() bool { return c.owner != nil }
func (c *BaseOpt) OwnerCmd() Cmd { return c.owner }
func (c *BaseOpt) Root() *RootCommand { return c.root } // returns Root CmdS (*RootCommand),
func (c *BaseOpt) App() App { return c.root.app } // App returns the current App
func (c *BaseOpt) Set() store.Store { return c.root.app.Store() } // Set returns store.Store associated with the current App
func (c *BaseOpt) Root() *RootCommand { return c.root } // returns Root CmdS (*RootCommand),
func (c *BaseOpt) App() App { return c.root.app } // App returns the current App
func (c *BaseOpt) Set() store.Store { return c.root.app.Store() } // Set returns the application Store [store.Store]
func (c *BaseOpt) Store() store.Store { return c.Set().WithPrefix("app.cmd") } // Store returns the commands subset of the application Store.
func (c *BaseOpt) SetOwner(o *CmdS) { c.owner = o }
func (c *BaseOpt) SetOwnerCmd(o Cmd) { c.owner = o }
func (c *BaseOpt) SetRoot(root *RootCommand) { c.root = root }
Expand Down
3 changes: 3 additions & 0 deletions cli/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ type Cmd interface {

// App() App

// Set returns the application Store [store.Store]
Set() store.Store
// Store returns the commands subset of the application Store.
Store() store.Store

OwnerIsValid() bool
OwnerIsNil() bool
Expand Down
2 changes: 1 addition & 1 deletion cli/worker/parse_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s *parseCtx) addFlag(ff *cli.Flag) (ms *cli.MatchState) {
}

// save the matched value into option store
cmdstore := ff.Set().WithPrefix("app.cmd")
cmdstore := ff.Store()
path := ff.GetDottedPath()
val := ff.DefaultValue()
cmdstore.Set(path, val)
Expand Down

0 comments on commit cefb7ab

Please sign in to comment.