Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter attributes aren't working #21

Open
GiscardBiamby opened this issue May 4, 2013 · 3 comments
Open

Parameter attributes aren't working #21

GiscardBiamby opened this issue May 4, 2013 · 3 comments

Comments

@GiscardBiamby
Copy link

I'm probably doing something wrong, but it seems like the Parameter attribute doesn't work. I made a test app with a Description property on some parameters, but the help text doesn't show the descriptions, it just shows the parameter Type. Also, I set a default on one of the parameters (int savedSearchId should default to 1), but the value comes in as zero.

This is what I get at the command line:
C:\projects\gbwork\CampaignEngine\src\hydra\bin\Debug>hydra

foo|f: Foo() description...

deletefromsavedsearch|d
/savedsearchid : (Int32)
/savedsearchname : (String)

Here is the code I'm using, it's in a .NET 4.5 Console App, and I added CLAP from nuget:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CLAP;

namespace hydra {
public class hydraConsole {
public static void Main(string[] args) {
Parser.Run(args);
}
}

public class hydraVerbs {

    [Verb(Description="Foo() description...")]
    public static void Foo() {
        Console.WriteLine("Foo!"); 
    }

    [Verb]
    public static void DeleteFromSavedSearch(
        [CLAP.Parameter(Description="Name of saved search with the users to delete")] 
        string savedSearchName

        , [CLAP.Parameter(Default = 1, Description = "Id of the saved search with the users to delete")] 
        int savedSearchId
    ) {
        Console.WriteLine("DeleteFromSavedSearch(savedSearchName: {0}, savedSearchId: {1}) !", savedSearchName, savedSearchId);
    }


    [Empty, Help]
    public static void Help(string help) {
        // this is an empty handler that prints
        // the automatic help string to the console.

        Console.WriteLine(help);
    }
}

}

@adrianaisemberg
Copy link
Owner

Please check if you get any compilation warnings. It is possible that the
attribute is obsolete. If it is - the warning message will give you the new
attribute names instead.
On May 4, 2013 8:17 AM, "GiscardBiamby" notifications@github.com wrote:

I'm probably doing something wrong, but it seems like the Parameter
attribute doesn't work. I made a test app with a Description property on
some parameters, but the help text doesn't show the descriptions, it just
shows the parameter Type. Also, I set a default on one of the parameters
(int savedSearchId should default to 1), but the value comes in as zero.

This is what I get at the command line:
C:\projects\gbwork\CampaignEngine\src\hydra\bin\Debug>hydra

foo|f: Foo() description...

deletefromsavedsearch|d
/savedsearchid : (Int32)
/savedsearchname : (String)

Here is the code I'm using, it's in a .NET 4.5 Console App, and I added
CLAP from nuget:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CLAP;

namespace hydra {
public class hydraConsole {
public static void Main(string[] args) {
Parser.Run(args);
}
}

public class hydraVerbs {

[Verb(Description="Foo() description...")]
public static void Foo() {
    Console.WriteLine("Foo!");
}

[Verb]
public static void DeleteFromSavedSearch(
    [CLAP.Parameter(Description="Name of saved search with the users to delete")]
    string savedSearchName

    , [CLAP.Parameter(Default = 1, Description = "Id of the saved search with the users to delete")]
    int savedSearchId
) {
    Console.WriteLine("DeleteFromSavedSearch(savedSearchName: {0}, savedSearchId: {1}) !", savedSearchName, savedSearchId);
}


[Empty, Help]
public static void Help(string help) {
    // this is an empty handler that prints
    // the automatic help string to the console.

    Console.WriteLine(help);
}

}

}


Reply to this email directly or view it on GitHubhttps://github.com//issues/21
.

@GiscardBiamby
Copy link
Author

Thanks, that fixed it. I think the documentation needs updating. BTW, I've tried several other command line parser libs the past couple of days and so far this is the best, and requires the least amount of boiler plate code to use. Thanks a lot for creating and maintaining it!

Here's what I changed the code to to get default values and auto help text working:

namespace hydra {
    public class hydraConsole {
        public static void Main(string[] args) {
            Parser.Run<hydraVerbs>(args);
        }
    }

    public class hydraVerbs {

        [Verb(Description = "Foo() description...")]
        public static void Foo([DefaultValue(22)] int height) {
            Console.WriteLine("Foo(height: {0})", height);
        }

        [Verb]
        public static void DeleteContacts(
            [Description("Name of saved search with the users to delete")] 
            string savedSearchName

            , [DefaultValue(1), Description("Id of the saved search with the users to delete")] 
            int savedSearchId
        ) {
            Console.WriteLine("DeleteContacts(savedSearchName: {0}, savedSearchId: {1}) !", savedSearchName, savedSearchId);
        }

        [Empty, Help(Aliases = "?,help,h")]
        public static void Help(string help) {
            Console.WriteLine(help);
        }
    }
}

@adrianaisemberg
Copy link
Owner

Cheers!
BTW, try RunConsole instead of Run. It gives you some built-in stuff. I
think the doc says something about it. Its been a long time since I updated
the docs.
On May 4, 2013 9:07 PM, "GiscardBiamby" notifications@github.com wrote:

Thanks, that fixed it. I think the documentation needs updating. BTW, I've
tried several other command line parser libs the past couple of days and so
far this is the best, and requires the least amount of boiler plate code to
use. Thanks a lot for creating and maintaining it!

Here's what I changed the code to to get default values and auto help text
working:

namespace hydra {
public class hydraConsole {
public static void Main(string[] args) {
Parser.Run(args);
}
}

public class hydraVerbs {

    [Verb(Description = "Foo() description...")]
    public static void Foo([DefaultValue(22)] int height) {
        Console.WriteLine("Foo(height: {0})", height);
    }

    [Verb]
    public static void DeleteContacts(
        [Description("Name of saved search with the users to delete")]
        string savedSearchName

        , [DefaultValue(1), Description("Id of the saved search with the users to delete")]
        int savedSearchId
    ) {
        Console.WriteLine("DeleteContacts(savedSearchName: {0}, savedSearchId: {1}) !", savedSearchName, savedSearchId);
    }

    [Empty, Help(Aliases = "?,help,h")]
    public static void Help(string help) {
        Console.WriteLine(help);
    }
}

}


Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-17445573
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants