Giter VIP home page Giter VIP logo

Comments (7)

adamabdelhamed avatar adamabdelhamed commented on August 14, 2024

For question 1, yes, but not yet. The next update I publish will add a [HelpHook] attribute to your help property (more on that below). I added this in part because of your question (thanks). I will probably publish within a couple of weeks. I'll leave this issue open until then.

For question 2, boolean properties already work that way.

If the user doesn't specify '-help' at all then the Help Property will have a value of false.
If the user types '-help' then it will have a value of true.
If the user types '-help true' then it will have a value of true.
If the user types '-help false' then it will have a value of false.

If you use the new [HelpHook] I talk about above then whenever the user indicates 'true' for the help property then it will not only have a value of true, but it will stop processing so the system does not try to invoke an action. It will finally print the help automatically for you (which you can turn off if you want to print it yourself).

from powerargs.

Geraint87 avatar Geraint87 commented on August 14, 2024

Looks good!

Is there a way though, that you could change the context if an action is specified?

e.g.

superencoder -help

Writes the full usage text - context = SuperEncoderArgs

superencoder encode -help

Only writes the usage text of EncoderArgs, not SuperEncoderArgs

superencoder clip -help

Similarly, only writes the usage text of ClipArgs.

from powerargs.

adamabdelhamed avatar adamabdelhamed commented on August 14, 2024

That's a good idea for a feature. I've thought of it before, but nobody asked for it until now. Let's leave this issue open until I can get to it.

from powerargs.

Geraint87 avatar Geraint87 commented on August 14, 2024

Looking at how git behaves, I wonder if the behaviour could be:

superencoder -help

Shows the list of Actions and their ArgDescriptions only ([Optionally or otherwise] does not recursively drill down into their properties)

superencoder encode -help

Shows the usage text of EncodeArgs, as mentioned before.

What do you think?

from powerargs.

adamabdelhamed avatar adamabdelhamed commented on August 14, 2024

Sorry for the delay. I think that sounds good. Another person opened a similar issue recently. Hopefully I can get to this soon.

from powerargs.

adamabdelhamed avatar adamabdelhamed commented on August 14, 2024

This is now working. Below is an example that shows how to manually use the usage API to set the specified action in the context of an exception. The default exception behavior now works like you asked in your last message. That is, if you're using the Args.InvokeAction() method, and you are using the [ArgExceptionBehavior(ArgExceptionPolicy.StandardExceptionHandling)] attribute on your main class then by default only the action specific usage will be printed when the error is in the context of an action. I'll leave the issue open until the next NuGet publish,

    public void TestActionSpecificUsage()
    {
        try
        {
            Args.InvokeAction<ArgsForActionSpecificUsage>("Foo");
        }
        catch (ArgException ex)
        {
            var usage = ArgUsage.GetStyledUsage<ArgsForActionSpecificUsage>("test", new ArgUsageOptions()
            {
                SpecifiedActionOverride = ex.Context.SpecifiedAction
            });
            Assert.IsTrue(usage.Contains("Foo"));
            Assert.IsFalse(usage.Contains("Bar"));
        }
    }

from powerargs.

adamabdelhamed avatar adamabdelhamed commented on August 14, 2024

Fixed

from powerargs.

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.