Coder Social home page Coder Social logo

clicommandlineparser's Introduction

Microsoft.DotNet.Cli.CommandLine

The command line parser currently used by the .NET CLI in older versions of the .NET SDK. Starting in 6.0.100, all versions have moved over to System.CommandLine listed below.

Note: For general use, we recommend System.CommandLine over this library.

Build Status

Latest Daily Build
main

clicommandlineparser's People

Contributors

chcosta avatar crummel avatar dotnet-bot avatar dotnet-maestro[bot] avatar dsplaisted avatar ellismg avatar johnbeisner avatar johntortugo avatar jonsequitur avatar livarcocc avatar marcpopmsft avatar michaelsimons avatar mmitche avatar nguerrera avatar seancpeters avatar tannergooding avatar terrajobst avatar tmat avatar trydis 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clicommandlineparser's Issues

System.IndexOutOfRangeException from Microsoft.DotNet.Cli.CommandLine.StringExtensions.HasPrefix

>dotnet.exe msbuild ""
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.String.get_Chars(Int32 index)
   at Microsoft.DotNet.Cli.CommandLine.StringExtensions.HasPrefix(String arg)
   at Microsoft.DotNet.Cli.CommandLine.StringExtensions.<Lex>d__7.MoveNext()
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Collections.Generic.Queue`1..ctor(IEnumerable`1 collection)
   at Microsoft.DotNet.Cli.CommandLine.Parser.Parse(IReadOnlyCollection`1 rawArgs, Boolean isProgressive)
   at Microsoft.DotNet.Cli.CommandLine.Parser.Parse(String[] args)
   at Microsoft.DotNet.Cli.ParserExtensions.ParseFrom(Parser parser, String context, String[] args)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

CliCommandLineParser fails to build with the latest .NET 6.0 SDK

  /repos/installer/artifacts/tarball/.dotnet/sdk/6.0.100-rc.2.21426.20/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): error NETSDK1138: The target framework 'netcoreapp2.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/repos/installer/artifacts/tarball/src/clicommandlineparser.3198bf5660cad3dab85f5475bf1fda9688146e3f/artifacts/source-build/self/src/src/tests/CommandLine.Tests/Microsoft.DotNet.Cli.CommandLine.Tests.csproj]
  /repos/installer/artifacts/tarball/.dotnet/sdk/6.0.100-rc.2.21426.20/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): error NETSDK1138: The target framework 'netcoreapp2.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/repos/installer/artifacts/tarball/src/clicommandlineparser.3198bf5660cad3dab85f5475bf1fda9688146e3f/artifacts/source-build/self/src/src/tests/CommandLine.Tests/Microsoft.DotNet.Cli.CommandLine.Tests.csproj]
  /repos/installer/artifacts/tarball/.dotnet/sdk/6.0.100-rc.2.21426.20/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): error NETSDK1138: The target framework 'netcoreapp2.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/repos/installer/artifacts/tarball/src/clicommandlineparser.3198bf5660cad3dab85f5475bf1fda9688146e3f/artifacts/source-build/self/src/src/xamples/dotnet/dotnet.csproj]
  /repos/installer/artifacts/tarball/.dotnet/sdk/6.0.100-rc.2.21426.20/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): error NETSDK1138: The target framework 'netcoreapp2.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/repos/installer/artifacts/tarball/src/clicommandlineparser.3198bf5660cad3dab85f5475bf1fda9688146e3f/artifacts/source-build/self/src/src/xamples/dotnet/dotnet.csproj]
  /repos/installer/artifacts/tarball/.dotnet/sdk/6.0.100-rc.2.21426.20/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): error NETSDK1138: The target framework 'netcoreapp2.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/repos/installer/artifacts/tarball/src/clicommandlineparser.3198bf5660cad3dab85f5475bf1fda9688146e3f/artifacts/source-build/self/src/src/xamples/SampleParsers/CommandLine.SampleParsers.csproj]

This is required for source build.

Conflict between Command and Opinion with same name

This happened on trying to convert dotnet help command, since there is a help command and a help opinion(--help). The repro is in this commit

        [Fact]
        public void Option_and_Command_can_have_the_same_alias()
        {
            Action a = () => new Parser(
                Command("outer", "",
                    ExactlyOneArgument(),
                    Command("inner", "",
                        ZeroOrMoreArguments()), Option("--inner", "")));
            a.ShouldNotThrow<ArgumentException>();
        }

SourceCode build failures in 'prodcon/clicommandlineparser/release/2.1.3xx/' - '20180507.02'

There were a set of failures during this build. Here is a summary of these:

@mmitche, @livarcocc

Doesn't work with some parameter values

For example I have an option defined as:

Option SourceOption() => Option("pattern", "", ExactlyOneArgument());

I cannot indicate empty string, only white spaces or "-" to it. We have some scenarios like to transfer file with specific name like "-" or to clean up some properties with indicating empty string. It's very useful for us to allow these special strings as parameter values.

Is there any reason why you forbid these strings?

LegalFilePathsOnly_rejects_arguments_containing_invalid_path_characters failing after update to .NET SDK RC1

https://ci.dot.net/job/dotnet_CliCommandLineParser/job/release_2.1.3xx/job/debug_windows_nt_x64_prtest/17/artifact/artifacts/Debug/TestResults/Microsoft.DotNet.Cli.CommandLine.Tests_netcoreapp2.0_x64.log

      Expected collection {empty} to be equivalent to {"|||"}, but it misses {"|||"}.
      Stack Trace:
        C:\projects\fluentassertions-vf06b\Src\FluentAssertions.Net45\Execution\XUnit2TestFramework.cs(32,0): at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
        C:\projects\fluentassertions-vf06b\Src\Core\Execution\AssertionScope.cs(197,0): at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
        C:\projects\fluentassertions-vf06b\Src\Core\Collections\CollectionAssertions.cs(364,0): at FluentAssertions.Collections.CollectionAssertions`2.BeEquivalentTo[T](IEnumerable`1 expected, String because, Object[] becauseArgs)
        C:\projects\fluentassertions-vf06b\Src\Core\Collections\StringCollectionAssertions.cs(41,0): at FluentAssertions.Collections.StringCollectionAssertions.BeEquivalentTo(String[] elements)
        /_/src/tests/CommandLine.Tests/ParsingValidationTests.cs(116,0): at Microsoft.DotNet.Cli.CommandLine.Tests.ParsingValidationTests.LegalFilePathsOnly_rejects_arguments_containing_invalid_path_characters()
      Output:
        124
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

The test is now skipped.

NormalizeRootCommand throws if no arguments

The args.First() line will throw if there are no args. Additionally, maybe there should be a TreatNoArgsAsError option on the root command so that ParseResults comes back with something useful we can handle. I guess we could just check ParseResults.Tokens.Count > 0. Might be a helpful extension or property on ParseResults.

Case-insensitive aliases

Is there any interest in optionally allowing aliases to be considered case-insensitive? There's been some talk about wanting it in dotnet new. I'd be happy to make a PR for this functionality. I know that you have an overall general plan for programmatically exposing more parse options. So I'd definitely want to work with you / follow your ideas for whatever API changes would be needed.

Any possible to support string starts with "-" as parameter value?

Following code throws an error of "Required argument missing for option: --include" with parse arguments "--include -", seems it doesn't recognize "-" as parameter value. I understand "-" is used as parameter prefix. Could you help to take a look whether there's any solution to let it recognize "-"?

            Option[] SampleOptions() => new Option[] {Option("--include",
                   "", // help here
                   ExactlyOneArgument().With(name: "Pattern"))};

            Parser Instance = new Parser(
                options: SampleOptions());
            ParseResult result = Instance.Parse(args);

Give more information to suggestion function

As far as I can tell, when specifying ArgumentsRule for an argument, the options for specifying suggestions are:

  • static list: public static ArgumentsRule WithSuggestionsFrom(this ArgumentsRule rule, params string[] values)
  • dynamic list based on the current value of the argument: public static ArgumentsRule WithSuggestionsFrom(this ArgumentsRule rule, Func<string, IEnumerable<string>> suggest)

But for https://github.com/dotnet/cli/issues/9172, I would like for the suggestion function to know not just the value of the argument being suggested, but also values of other arguments. That way, e.g. dotnet add package Microsoft.CodeAnalysis -v <Tab> could get the name of the package (Microsoft.CodeAnalysis) to query an API for a list of its versions.

The necessary information seems to be already contained in the ParseResult that's passed to ArgumentsRule.Suggest(), but there doesn't seem to be a way to access that from the suggestion function.

Or am I missing something and there is already a way to do this?

Upgrade Arcade to 6.0

Arcade in CliCommandLineParser is currently 1.0:

"Microsoft.DotNet.Arcade.Sdk": "1.0.0-beta.19207.1"

Arcade-powered source-build requires Arcade 6.0, which is the new LTS version. We will need to upgrade to 6.0 to support arcade-powered source-build.

cc @wli3

Sample for AnyOneOf doesn't work as expected

From the Dotnet Parser sample:

 private static Option VerbosityOption() =>
            Option("-v|--verbosity",
                   "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]",
                   AnyOneOf("q[uiet]",
                            "m[inimal]",
                            "n[ormal]",
                            "d[etailed]"));

and passing the following args to the parser (like a parser in that example)

{ "--verbosity", "q"}
{ "--verbosity", "quiet"}

Expected behavior

The switch argument recognized and returned as the value.

Actual behavior

For the switch argument to be returned, it must be passed like:

{ "--verbosity", "q[uiet]"}

This is consistent with the tests, not consistent with user expectations.
From the test for AnyOneOf

       [Fact]
        public void Applied_option_with_specific_arguments_does_not_accept_argument_that_does_not_match()
        {
            var option = Option("-x", "", AnyOneOf("one", "two", "three"));

Short term action

Mark that example as problematic

I think this also needs to be fixed.

Publishing build failures in 'prodcon/clicommandlineparser/release/2.1.3xx/' - '20180511.02'

@dotnet-mc-bot commented on Fri May 11 2018

There were a set of failures during this build. Here is a summary of these:

@mmitche, @livarcocc

How to allow spaces in option input

Often when handling file path input there could be spaces in the path c:\my test folder\myfile.txt that is often fixed by using " like so "c:\my test folder\myfile.txt" But the CliCommandLineParser dosent allow that. Is it possible somehow?

CliCommandLineParser Usuage Example

Hello,

Do you guys maybe have a usage example for this library or known apps that uses CliCommandLineParser

Been trying to find a good commandline parser for .Net Core console application would like to see in example how this works,

SourceCode build failures in 'prodcon/clicommandlineparser/release/2.1.3xx/' - '20180519.01'

There were a set of failures during this build. Here is a summary of these:

@mmitche, @livarcocc

Build does not publish packages to a NuGet feed.

The packages produced by the official build are not getting published to a NuGet feed. This blocks downstream repos from consuming the packages.

This is blocking the ArPOW source-build work.

XUnit build failures in 'prodcon/clicommandlineparser/release/2.1.3xx/' - '20180530.01'

There were a set of failures during this build. Here is a summary of these:

@mmitche, @livarcocc

Options should require that they are specified again in order to add additional arguments for that option

For example, consider the following:

> some-command -x arg1 arg2

Assuming that both some-command and -x accept arguments, this should parse as:

[ some-command [ -x <arg1> ] <arg2> ]

but it parses as:

[ some-command [ -x <arg1> <arg2> ] ]

Achieving the latter result should require that -x is specified a second time, like this:

> some-command -x arg1 -x arg2

Related: https://github.com/dotnet/cli/issues/6191

ParsingValidationTests failure in prodcon

The When_no_option_accepts_arguments_but_one_is_supplied_then_an_error_is_returned parsing validation test is failing in prodcon with:

<test name="Microsoft.DotNet.Cli.CommandLine.Tests.ParsingValidationTests.When_no_option_accepts_arguments_but_one_is_supplied_then_an_error_is_returned" type="Microsoft.DotNet.Cli.CommandLine.Tests.ParsingValidationTests" method="When_no_option_accepts_arguments_but_one_is_supplied_then_an_error_is_returned" time="0.0448245" result="Fail">
  <failure exception-type="Xunit.Sdk.XunitException">
    <message><![CDATA[Expected collection to contain a single item matching (e == \"Unrecognized command or argument 'some-arg'\"), but no such item was found.]]></message>
    <stack-trace><![CDATA[   at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions.Net45\Execution\XUnit2TestFramework.cs:line 32
                             at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in C:\projects\fluentassertions-vf06b\Src\Core\Execution\AssertionScope.cs:line 197
                             at FluentAssertions.Collections.SelfReferencingCollectionAssertions`2.ContainSingle(Expression`1 predicate, String because, Object[] becauseArgs) in C:\projects\fluentassertions-vf06b\Src\Core\Collections\SelfReferencingCollectionAssertions.cs:line 492]]></stack-trace>
  </failure>
</test>

The test is not failing locally in any of the configurations I tested.

Official CI is failing

  Running tests: C:\A\1\17\s\artifacts\bin\Microsoft.DotNet.Cli.CommandLine.Tests\Release\Microsoft.DotNet.Cli.CommandLine.Tests.dll [netcoreapp2.1|x64]
XUnit : error : Tests failed: C:\A\1\17\s\artifacts\log\Release\Microsoft.DotNet.Cli.CommandLine.Tests_netcoreapp2.1_x64.log [netcoreapp2.1|x64] [C:\A\1\17\s\src\tests\CommandLine.Tests\Microsoft.DotNet.Cli.CommandLine.Tests.csproj]
##[error]XUnit(0,0): error : (NETCORE_ENGINEERING_TELEMETRY=Test) Tests failed: C:\A\1\17\s\artifacts\log\Release\Microsoft.DotNet.Cli.CommandLine.Tests_netcoreapp2.1_x64.log [netcoreapp2.1|x64]

Build FAILED.

https://dnceng.visualstudio.com/internal/_build/results?buildId=1172063&view=logs&j=16ce49ee-8d0d-5a76-4958-88f78392b71f&t=206012c0-0eaa-56aa-8172-665f354177dc (internal link)

cc @wli3

Create.Option accepts a materialize but does nothing with it

The helper method Create.Option can take an optional materialize argument but it does nothing with it. This stumped me a little bit as I thought I could do something like the following:

// this doesn't work
private static Option VersionOption() =>
      Create.Option("--version", "Show version information",
            materialize: o => "My Version 1.0.0");

// this works
private static Option VersionOption() =>
      Create.Option("--version", "Show version information",
            Accept.NoArguments().MaterializeAs(o => "My Version 1.0.0"));

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.