Code Monkey home page Code Monkey logo

commandline's People

Contributors

alexghiondea avatar fabsenet avatar hanabi1224 avatar lucyainsworth avatar slolife avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

commandline's Issues

Should Parse throw the exception?

Right now, calling Parse will return a null object if something bad happened during the parse.

An error message is displayed to the user that contains the exception.

However, there isn't a good way to catch the exception that was begin thrown from the parser.

Thoughts?

/cc @lucyainsworth @safern @hanabi1224

Invalid optional argument format syntax results in bad exception msg

Example:
<action_group_arg> <required_1> <required_2> <required_3> <optional_w_bad_syntax>

If someone were to supply a malformed optional argument such as "-option=value" then it will report that the previous argument was not found. In this case that is a required argument, so the error message is misleading & incorrect. This is caused by line 297 in Parser.cs, because it indexes into args with currentLogicalPosition without adding offsetInArray.

Using the above example syntax we can expand on the problem here:
Foo bar_req1 bar_req2 bar_re3 -optional=value

Would result in the following exception msg: "Could not find argument bar_req3"

NullRef in the analyzer

For code like this:

namespace DotNetVersions.Console
{
    class Options
    {
        [ArgumentGroup(nameof(Action.search))]
        [RequiredArgument(0, "version", "The file version  you are interested in")]
        public string Version { get; set; }

        [ActionArgument]
        public Action Action { get; set; }
    }

    enum Action
    {
        list,
        search
    }
}

There is a crash in the analyzer with this callstack:

Warning	AD0001	Analyzer 'CommandLine.Analyzer.CommandLineAnalyzer' threw an exception of type 'System.Collections.Generic.KeyNotFoundException' with message 'The given key was not present in the dictionary.'.	
'CommandLine.Analyzer.CommandLineAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: fooBar
ISymbol: Options (NamedType)

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at CommandLine.Analyzer.CommandLineAnalyzer.CreateArgumentMapForType(INamedTypeSymbol namedTypeSymbol, SymbolAnalysisContext context, ActionArgument& actionArg)
   at CommandLine.Analyzer.CommandLineAnalyzer.AnalyzeCommandLineType(SymbolAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__38_1(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
----

Suggestion to Call Help Manually

First off, great project, thanks. A suggestion though, if you don't mind me asking.

When i have my command line parsed, i will get a filepath; i then need to check this filepath exists and the config file at that location parses okay, if not then i want to be able to display an error and the Detailed Help already formatted as per an error generated from the parser.

Can you add this facility so that help can be called externally?

Add support for configuring parameters

When using parameters, sometimes you would need to tweak them based on some rules.

One example is the use of the output file. The user will provide a value for that, but what happens if the file already exists?

An approach is to automatically append a number to it until it creates a file name that no longer exists.

Other validations could be added -- what if a parameter can have a min/max value? That can be validated by the parser.

Couple of approaches:

  • Attributes that describe the behavior
  • Callbacks that are registered with the parser for validation

Allow overriding required position for arguments that are in multiple argument groups

    internal class CmdLineArgs
    {
        [ActionArgument]
        public Action Action { get; set; }

        [CommonArgument]
        [OptionalArgument(null, "token", "The GitHub authentication token. If not specified, we will authorize to GitHub.")]
        public string Token { get; set; }

        [ArgumentGroup(nameof(Action.List))]
        [RequiredArgument(0, "repos", "The list of repositories where to add the milestones to. The format is: owner\\repoName.", true)]
        public List<string> Repos { get; set; }

        [ArgumentGroup(nameof(Action.Create))]
        [RequiredArgument(0, "milestoneInputFile", "The file containing the list of milestones to create.")]
        public string MilestoneFile { get; set; }

        [ArgumentGroup(nameof(Action.Create))]
        [RequiredArgument(1, "repos", "The list of repositories where to add the milestones to. The format is: owner\\repoName.", true)]
        public List<string> Repositories { get; set; }
    }

    public enum Action
    {
        Create,
        List
    }

In the above example, I would like the Repositories property to be required at position 1 in the Create group and position 0 in the List

This could be achieved by adding an argument on the ArgumentGroup attribute:

        [ArgumentGroup(nameof(Action.Create), OverrideRequiredPosition=0)]

V2 feature list

  • Support .NET Standard 2.0 #43
  • Ensure that TryParse never throws an exception #40
  • Ensure that Parse always throws the exception #40
  • Add support for retrieving values for the optional arguments from the environment
  • Ensure that the parser is configurable
    • Add support for not logging to the console in case of error
    • Add support for specifying the prefix for env-vars
  • Support for parameter validation / configuration #44

When pass down more than the maximum accepted parameters, fails with IndexOutOfRange

E:\repos\ApplyNullableDecorators\src>apply-nullable-decorators apply E:\repos\coreclr\src\System.Private.CoreLib\System.Private.CoreLib.csproj System.Int32 santi -msbuild ""
Error: Index was outside the bounds of the array.

Usage:
 apply-nullable-decorators.exe apply project type [-msbuild value]
 apply-nullable-decorators.exe apistats project jetbrainsfiles [-msbuild value]

For detailed information run 'apply-nullable-decorators --help'.

Using enum values as lowercase

Example:

         /// <summary>
        /// Type of action by files
        /// </summary>
        [RequiredArgument(0, "action", "what need do: convert or unconvert")]
        public ActionType ActionType { get; private set; }

       /// <summary>
       /// Action type
       /// </summary>
       public enum ActionType
       {
        Convert,
        UnConvert
       }

if i used program.exe convert - it generate error, but if used program.exe Convert work right

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.