Comments (8)
I think your scenarios different than what I’m used to. So I probably don’t understand it well. Here’s how I imagine things.
# implies follow is enabled
# this is actually what you have now
myapp logs
# if you remove your follow flag,
# and instead have a no-follow flag
# this will disable follow
myapp logs --no-follow
from cobra.
I see your point. Thanks for the explanation. To do this automatically would require a flag rapper API because the flags are handled by the spf13/pflag project directly.
from cobra.
Although this sounds like a good idea, I wonder if it’s needed in practice.
In your above example, the —follow
flag has a default value of true. This implies that the user does not need to specify it in the command line for it to be “turned on”. In such a case maybe it’s simply better to have the flag be —no-follow
with a default value of false.
from cobra.
Actually I want follow
to be the default because I generally follow logs in docker.
So --no-follow
would override it. If I created a no-follow
flag I'd have to think of the situation of something crazy like this myself.
docker service logs --follow --no-follow --follow --follow=false --follow --no-follow
Or at the very least assume that this is not "normal" behaviour (note with ls
they allow switching things on and off on the same command and the last value before --
wins. That last statement I think could be another Issue that should be raised.
from cobra.
@marckhouzam you have a correct example. The main purpose I see is the use of shell aliases.
The concept is to allow someone to say the following (which I sort of do as well)
Say
alias ls=ls -FCs
Then if I do
ls -1
it translates to
ls -FCs -1
So the 1
overrides the C
parameter.
But with the no-prefix
we can have the concept of follow
being false by default
for example
docker service logs
will not do follow, but if I do an alias to make it follow
alias dsl="docker service logs --follow"
If I want to remove the follow for a command I would have no capability without retyping the whole command. If I had that --no-follow
then I can simply
dsl --no-follow
which translates to
docker service logs --follow --no-follow
And the command line processor will take the "last" version of the flag so make it equivalent to
docker service logs --no-follow
from cobra.
This is the equivalent in python argparse
from cobra.
Can you move this ticket there?
from cobra.
Sorry but I’m not a maintainer for spf13/pflag
from cobra.
Related Issues (20)
- 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
- 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
- Add EnableFlagSorting similar to EnableCommandSorting
- non-boolean flags found on sub commands regardless of order HOT 4
- Fish completion fails due to `eval` and subshell execution during completion HOT 1
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.