Code Monkey home page Code Monkey logo

Comments (8)

marckhouzam avatar marckhouzam commented on June 8, 2024 1

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.

marckhouzam avatar marckhouzam commented on June 8, 2024 1

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.

marckhouzam avatar marckhouzam commented on June 8, 2024

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.

trajano avatar trajano commented on June 8, 2024

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.

trajano avatar trajano commented on June 8, 2024

@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.

trajano avatar trajano commented on June 8, 2024

This is the equivalent in python argparse
image

from cobra.

trajano avatar trajano commented on June 8, 2024

Can you move this ticket there?

from cobra.

marckhouzam avatar marckhouzam commented on June 8, 2024

Sorry but I’m not a maintainer for spf13/pflag

from cobra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.