Comments (13)
Perhaps an alternative Run command, e.g:
RunWithError: func(cmd *cobra.Command, args []string) error {
(not the best name to be sure)
from cobra.
👍 this is very welcomed. I cringe everytime I have to do error processing on my inner functions. :D
from cobra.
Yes, well - I don't see a way to change this without breaking a lot of user code ...
To my surprise, the "other Go CLI framework", seems to be doing exactly the same.
from cobra.
A little surprised to see so little interest in this issue.
@eparis what do you to handle this problem? Handle all errors inside the commands?
from cobra.
For the most part, everything I do called
if err := cmd.Execute(); if err != nil {
os.Exit(1)
}
os.Exit(0)
And inside run we've got glog.Fatal() (which does os.Exit(1) on unhandl-able errors)
from cobra.
I would agree with this but it would be a breaking news change. We should always populate the errors up. @eparis a good use case would be testing but also populating the errors up would allow for a single error handling for parent and child commands as well.
from cobra.
Agreed, I'm using a fork for the time being. I prefer to have a single os.Exit on a single error exit point.
https://github.com/pgruenbacher/cobra
from cobra.
So I don't think we can/should change Run
. Too many people are using it I'd expect. Maybe we should add a RunE
or something like that? Same thing as run but which returns an error
which gets populated back up through Execute()
?
from cobra.
https://gist.github.com/eparis/be6ca4c767e69fcaaea8 ?? Maybe something like that?
from cobra.
@eparis agree. RunE
also matches the naming convention I've seen elsewhere in situation like this.
from cobra.
@eparis @bep I agree. That works if we want to use that but I think it would be better in the longer term to make that the default. Possibly a deprecation period?
from cobra.
I think that the only thing is that patch would need to have is these: PostRunE
, PersistentPostRunE
, PreRunE
and PersistentPreRunE
to achieved the full desired effect.
from cobra.
@bep @eparis I think this should be good to close with the fix from Alex, right?
from cobra.
Related Issues (20)
- The package path of the official website documentation is wrong HOT 2
- Command suggestions not working for nested commands HOT 1
- Always got default value from flag HOT 1
- Completion should not complete the --help/-h and --version/-v flags if DisableFlagParsing==true
- Prevent default help command and flag
- Investigate G602 bypass fix
- Cobra SetUsageTemplate() overrides the help message HOT 1
- ActiveHelp on bash does not handle command-line prefixes adequately
- Can there be support for "Parameter sets" if there isn't already? HOT 1
- command PreRun don't run when to use [ app install phase -f ],otherwie PreRun is running when to use [ app install -f ] HOT 2
- Nested Query To set value HOT 1
- Nested Query using set function HOT 2
- Add a `no-` version of a boolean HOT 8
- Child command context is not updated when global context changed HOT 2
- [Bug] SetArgs doesn't reset flag value HOT 9
- A research for generating PR checklists in Pull Request Template
- shorthand not working and throw panic while use name works HOT 2
- Plugins: add map to store arbitrary data in `Command` HOT 1
- [doc] Add support for taking in `text/template`s for generating docs HOT 1
- docs: Content of user_guide.md not published at cobra.dev
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 cobra.