Comments (7)
@shrimalmadhur The AfterFunc will be run only once after the subcommand actions have been completed. So in your case of cmd operation1 operation2
the AfterFunc defined for "cmd" will be executed once in the same command context after actions for operation1, operation2 have been completed. I am not entirely clear what you want to achieve. If you want a single function to handle all your actions you could attach the same function to all the Actions/After/Before for each of the subcommands individually. There is no way for the cli library to do this automatically for you
from cli.
@dearchap thanks for the answer. my detailed case is I want to send telemetry data to an endpoint after any command gets executed - I need the whole command path while sending telemetry.
From what you are saying every I add a new command I will have to mention that function in After
field. The thing which I wanted to achieve is that I just define that in root
command and since it gets executed every time - the context would have that information.
But I guess I understand that the context is very specific to each command for AfterFunc
from cli.
Yes that's correct. If you pass in the same function in all the places the context for the command will be passed to you
from cli.
I see but interestingly I found an issue in v2.27.2
// FullName returns the full name of the command.
// For subcommands this ensures that parent commands are part of the command path
func (c *Command) FullName() string {
if c.commandNamePath == nil {
return c.Name
}
return strings.Join(c.commandNamePath, " ")
}
This always returns only the leaf command path but it's supposed to return whole command path. I don't see c.commandNamePath
set somewhere.
In the latest master branch, the code is
// FullName returns the full name of the command.
// For commands with parents this ensures that the parent commands
// are part of the command path.
func (cmd *Command) FullName() string {
namePath := []string{}
if cmd.parent != nil {
namePath = append(namePath, cmd.parent.FullName())
}
return strings.Join(append(namePath, cmd.Name), " ")
}
This will insure parent command path is also included
from cli.
ok c.Command.HelpName
actually gives the full command I need. I can wait for v3 to get released for using the FullName()
feature.
from cli.
@shrimalmadhur you can start using v3, It is almost production ready.
from cli.
@dearchap oh awesome. excited for using v3. Thanks for the update, I will close this issue now.
from cli.
Related Issues (20)
- How do I define Usage for BoolWithInverseFlag? HOT 23
- Shell completions are broken when login shell is different than currently active shell
- Use mkdocs `mike` for multi-version docs
- Strictly limit default dependencies to stdlib HOT 6
- Build out all of the v3 documentation
- Vendor usage of `github.com/xrash/smetrics` for suggestions HOT 2
- Delete stale branches HOT 5
- Use gofumpt
- Man page generation feature is not documented anywhere HOT 3
- Doc generation default value set by environment variable HOT 4
- Expose shell completions scripts in by default in the `completion` command HOT 5
- More powerful shell completion HOT 2
- Ensure `go mod tidy` works as expected HOT 1
- Target `stable` and `oldstable` in main CI
- Flags are alphabetically sorted when using categories HOT 3
- Should I expect completion of nested command's flags to work? HOT 31
- Remove [command [command options]] from help text if there are no sub commands HOT 3
- Default `cli.App.Usage` behaviour is very hard to override and leads to ugly help HOT 1
- Allow omission of default text in help text HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli.