Skip to content

Ideas for possible some improvements #32

@Rast1234

Description

@Rast1234

Hello. I am writing an utility and i decided to use your library. Right now i have 4 issues and maybe something can be improved, if you'd like:

  1. The idea of commands is very nice. However, right now i can't have multiple commands and run one command by default (when no args specified). Yes, this might be cryptic for users, but it's normal behavior for GUI apps (like Process Explorer and other Sysinternals tools): it runs normally by default, but if you pass args, it displays help in MessageBox or does what args tell it to do.
    Right now i'm using this hack:

    • if there are no args
    • or if there are args, and if first arg is not a command (checking by using copy of private static GetMatchingCommand because it's private!)
    • and arg[0] is not help
    • then insert name of default command to args[0]
    • then let your library do all the job like normal

    So i think you can add an optional argument to DispatchCommand or add metadata field to command to allow some command run as default one.

  2. As i mentioned, i'm writing a GUI app. I don't need int return code, and my main has void return type. If everything was ok, app does nothing, otherwise it displays a MessageBox with message and icon. However, can't return more than int from a command. Right now i just have public static MyResult Result {get; set;} field in Program class and set it from commands which is obviously too ugly. Maybe you can introduce generic ConsoleCommand<T> to allow users to return any type?

  3. I have strange behavior with setting default value for optional argument. If i don't specify the value, it is null every time. Maybe that's intended, but i expected from docs that Action gets called and i can check for null and set default value from there. For example:

    HasOption("c|config:", "Config file", x => ConfigFileName = x ?? "test");
    

    ConfigFileName is not set from this Action, i need to back it up with default value elsewhere.

  4. I can't get : or = in prototype to show default value instead of VALUE. Like in example above, i have in generated help: -c, --config[=VALUE] Config file. Am i missing something? I'd like it to be -c, --config[=test] Config file but when i specify "c|config:test", i gen an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions