Coder Social home page Coder Social logo

reubeno / nclap Goto Github PK

View Code? Open in Web Editor NEW
52.0 5.0 12.0 947 KB

NClap is a .NET library for parsing command-line arguments and building interactive command shells. It's driven by a declarative attribute syntax, and easy to extend.

License: MIT License

C# 99.84% Dockerfile 0.16%
command-line-parser csharp reflection repl argument-parsing dot-net

nclap's People

Contributors

cjoprey avatar dependabot[bot] avatar gitter-badger avatar jonathantims avatar murmelnash avatar reubeno 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

Watchers

 avatar  avatar  avatar  avatar  avatar

nclap's Issues

Remark advertising /? is missing text

The text output says something like:

For more information, type: "Program.exe"

It should really say:

For more information, type: "Program.exe /?"

Autocomplete from Array

Is there any way to "autocomplete" the possible values of a NamedArgument from an array instead of a ENUM? Since it is dynamic in runtime, it will be great to autocomplete from a dynamic resource.

Not compatible with Mono

Mono seems to not give GUIDs for primitive types.

I.e, typeof(int).GUID will return GUID.Empty; the causes Type initialization to fail in static class ArgumentType's static constructor.

Set of questions using Loop

I am using Loop interface. I have some issues with the style "--" , help and autocomplete:

  1. HELP command is not showing examples using Loop.

  2. Cannot get the Loop working with "--" GetOpt style

[ArgumentSet(
        Style = ArgumentSetStyle.GetOpt,
        Description = "You are cool command.",
        Examples = new string[]
        {
            "cool --myvalue ",
            "",
        })]
class MyCoolCommand : SynchronousCommand
{ ... }
 var setAtt = new ArgumentSetAttribute()
            {
                Style = ArgumentSetStyle.GetOpt,
                NamedArgumentPrefixes = new [] { "--" },
                ShortNameArgumentPrefixes = new [] { "-" },
            };

Any ideas?

Changing Prompt string in runtime with ColoredString, take the string but no color

I want to show some session info in the prompt string (such as git bash for example).
Depending on a session state, I need to change the Prompt string.

int status=1;
_myLoopClient.Prompt = new NClap.Utilities.ColoredString($"stat({status})$ ", ConsoleColor.Blue);

The prompt change successfully but the COLOR does not refresh to the selected one. It remains in the default color.

.net 5.0: No matching command constructor could be found on type

I have a weird instantiation bug since I ported to .net5. Happens only with the HelpCommand<> class

public enum ApiCommands
{
  [HelpCommand(ShortName = "h", LongName = "help", Description = "Help")]
  Help,
}

an exception is raised at CommandGroupArgumentType@106

            try
            {
                return commandGroupConstructor.Invoke(new[] { groupOptions, selection, context.ContainingObject });
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }

StackTrace

   at NClap.Parser.CommandDefinition.Instantiate(ServiceConfigurer serviceConfigurer) in /.../NClap/src/NClap/Parser/CommandDefinition.cs:line 61
   at NClap.Metadata.CommandGroup`1.InstantiateCommand(IEnumArgumentType commandTypeType, Object selection) in /.../NClap/src/NClap/Metadata/CommandGroup`1.cs:line 189
   at NClap.Metadata.CommandGroup`1.InstantiateCommand(Object selection) in /.../NClap/src/NClap/Metadata/CommandGroup`1.cs:line 162
   at NClap.Metadata.CommandGroup`1.set_SelectedCommand(Object value) in /.../NClap/src/NClap/Metadata/CommandGroup`1.cs:line 154
   at NClap.Metadata.CommandGroup`1..ctor(CommandGroupOptions options, Object selection, Object parentObject) in /.../NClap/src/NClap/Metadata/CommandGroup`1.cs:line 74

Allow customizing auto-generated logo strings

NClap currently has fixed logic for generating logo strings; it's overridable with a custom string, but some folks have said they like not having to generate it themselves... but would like a different format.

There's simple work we can do here to allow format strings, e.g.:

"{$title} v${version}"

I've already started on this work in a branch...

Exception in help command

When using a command loop calling help with an unknown command results in an System.NullReferenceException in Future.cs

Object reference not set to an instance of an object.
at NClap.Metadata.CommandGroup`1.get_Selection()

The minimal Program to show this behaviour is:

var loop = new Loop(typeof(CommandType));
loop.Execute();

public partial class Program
{
enum CommandType
{
[HelpCommand]
Help,

    [Command(typeof(ExitCommand))]
    Exit
}

}

Typing 'help exit' works as expected, typing 'help xxx' crashes.

Angle brackets around required param names not needed

Under the "REQUIRED PARAMETERS" section, there are angle brackets around the parameter's descriptive name (which isn't otherwise used in syntax), e.g.:

<MyArgument : <String>>

The angle brackets are helpful when this shows up in the SYNTAX section, but not under REQUIRED PARAMETERS -- it's on a line by itself. It should instead look like:

MyArgument : <String>

Persistent command history on Loop

Is it possible to make the command history persistent? Or save the commands entries to a local file?

In case there is not, can you provide Any example on how to access to the command history (_entries), and send a command to the prompt for execution?

What about supporting netstandard 2?

Can be added as an extra target. So for example dependency injection 2.1.1 (latest) will be used. For me (when using in a netcoreapp2) it always reverts back to 1.1.1

Allow option to parse into objects without any ArgumentAttribute attributes

Much like other serializers/deserializers, in this option/mode, we can assume that all writable public fields and properties are fair game (and mark all arguments as optional).

We can either take in flags to the parsing method calls to guide us through this, or else require a single ArgumentSetAttribute on the object's type in order to guide us. Or we can make the flags totally optional and just do the basic thing.

It's still up for call.

Revisit dynamic selection of ArgumentSet style based on host platform

It's certainly complicated our tests, and for tools expected to run on multiple host platforms, the default behavior of using different styles by default across them might be confusing. There's already a way for the program author to be explicit and select the same one across all, but we should probably revisit this decision.

Ideally, user feedback would be helpful here.

Unit tests fail if you have a non-US keyboard layout set

The following tests all have dependencies on a US keyboard layout:

  • InsertCommentButWithoutDefinedCommentChar
  • InsertCommentWithDefinedCommentChar
  • TestThatDigitKeysTranslateCorrectly
  • TestThatNumberedOemKeysTranslateCorrectly
  • TestThatTwoCodePathsAgree

I run on a UK keyboard layout, and all the above fail. These tests should be made keyboard layout agnostic.

Unable to use enum with aliases

Saw the exception below thrown when trying to parse an enum like this:

enum Foo
{
    SomeValue,
    AliasForSomeValue = SomeValue,

    OtherValue,
    AliasForOtherValue = OtherValue
}

Exception details:

Unhandled Exception: System.ArgumentException: An item with the same key has already been added.    at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](List`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at NClap.Types.EnumArgumentType..ctor(Type type)
   at NClap.Types.EnumArgumentType.Create(Type type)
   at NClap.Types.ArgumentType.TryGetType(Type type, IArgumentType& argType)
   at NClap.Types.ArgumentType.GetType(Type type)
   at NClap.Metadata.ArgumentBaseAttribute.GetArgumentType(Type type)
   at NClap.Parser.ArgumentDefinition..ctor(IMutableMemberInfo member, ArgumentBaseAttribute attribute, ArgumentSetAttribute setAttribute, CommandLineParserOptions options, Object defaultFieldValue, IMutableMemberInfo parentMember, Object fixedDestination)
   at NClap.Parser.ArgumentSetDefinition.CreateArgumentDescriptor(IMutableMemberInfo member, ArgumentBaseAttribute attribute, Object defaultValues, ArgumentSetAttribute setAttribute, CommandLineParserOptions options, Object fixedDestination)
   at NClap.Parser.ArgumentSetDefinition.CreateArgumentDescriptorsIfApplicable(IMutableMemberInfo member, Object defaultValues, ArgumentSetAttribute setAttribute, CommandLineParserOptions options, Object fixedDestination)
   at System.Linq.Enumerable.<SelectManyIterator>d__159`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at NClap.Parser.ArgumentSetDefinition.AddArgumentsFromTypeWithAttributes(Type defininingType, Object defaultValues, Object fixedDestination)
   at NClap.Parser.CommandLineParserEngine..ctor(Type type, Object defaultValues, CommandLineParserOptions options)
   at NClap.CommandLineParser.ParseWithUsage[T](IEnumerable`1 arguments, T destination, CommandLineParserOptions options, UsageInfoOptions usageInfoOptions)

Help with a wizard interface

Hi,

What I'm looking to do is create a simple CRUD console app where I'm planning on prompting the user for each field value, and using the tab autocomplete feature of NClap to do some lookups for things that would be human-readable values for things that would be normally foreign key numeric ids.

How would be the best way to have a series of predefined prompts. Would each prompt be a command in a loop? Or should a single command be used to handle all interactions specific to one row of data to add?

I know this isn't the ideal use case for a console app, but I've got a 2 day window to get this done for a hack-a-thon-esque project and I thought it sounded like fun.

Thanks!

Unit test for console scrolling always fails due to parameter validation

TestThatScrollingPositiveLinesEitherSucceedsOrThrowsNotSupportedException in WindowConsoleTests.cs (line 51) always fails.

The reason is as follows:

  • “console.ScrollContents(1)” calls “CursorTop -= lineCount” (WindowsConsole.cs, line 68)
  • CursorTop is based on “_cursorTop”
  • “_cursorTop” has a default value of zero, and a validator that it must be >= 0.
  • That first line I mentioned tries to set CursorTop to -1, so it will always fail.

The test indicates that if _consoleTop is set to a negative number, it should throw a NotSupportedException, rather than the ArgumentOutOfRangeException it throws now due to the validation failure.

Should we change the test, or should we change the code?

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.