Code Monkey home page Code Monkey logo

entrypoint's People

Contributors

bovorasr avatar nick-lucas 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

entrypoint's Issues

Issue with file paths

This might be me doing something very silly, so I apologise if that is the case but..

If I try and pass a file path as an operand (like c:\some\path) by the time it gets to the method that handles the command the slashes are removed.
If however I escape them in the input it works as intended. Is there a way around this? Its not too much of a big deal for me at the moment (as I am using this primarily on Linux at the moment so I am never encountering \ as a path separator) but it does mean that dragging and dropping files onto an exe with this setup doesn't work which is a shame.

Allow Options to Depend on or be Exclusive from other Options

A new Attribute to mark two options as exclusive, or strictly inclusive of another option would be useful for validation on the user side.

Something like:

OptionRelationship(
    Relationship = OptionRelationshipEnum.DependsOn | ExclusiveOf,
    OptionProperty = nameof(MyProperty))

.Net Arg Splitting Handles Quotes and basic Tokenisation

This will break EntryPoint as it stands, since arguments are combined again in order to be parsed.

As shown below, quoted sections get split, and lists are also split correctly.
Need to tweak tokenisation to expect these conditions

image

Source:

    public class Program {
        public static void Main(string[] args) {
            foreach (var arg in args) {
                Console.WriteLine($"Arg: {arg}");
            }
            Console.Read();
        }
    }

Support Mapping of Enums

Currently Ints will probably map fine to Enums, but strings may not.

Support for recognising and mapping these properly would be good

Improvements to Documentation Generator

  • Print Required status -o --option REQUIRED
  • Print whether a parameter is required, and what type it is -o --option [string]
  • Print a summary of CLI usage before breaking down options, like: Utility [-a] [-o | --option value] [operands]

Document UserFacingException

This exception is the base class for all exceptions which are intended to have their message displayed to the user

Allow operands to come before option tags

Currently the IEEE standard is enforced, where operands must come after everything else.

it is quite common on CLIs to support operands coming before options.

we should support this to increase usability

Todo - For 0.9.5

  • Update --help documentation to advise that dev should invoke generator in their own code, when the HelpRequested flag is set.

Rename Apis to final names

  • Rename EntryPointApi -> Cli
  • Rename BaseApplicationOptions -> BaseArguments
    • Cli.Parse -> ParseArguments
    • This is more general and accurate, since we now have Operands, and are introducing Commands.

Need to update documentation for all of this.

Some Tests need adding

  • Test combining single dash args
  • Test Quotes usage
  • Test = usage
  • That -h or --help will trigger a Model Exception for duplicate option

Help Generator Api Design

This is still not nailed down pre-1.0, and I'm not totally happy with the developer workflow.

Things like 'ignore required' when --help is invoked, leave EntryPoint in a footgun position, if a developer doesn't realise they should check .HelpRequested after parsing.

0.9.5 is out there, but may yet change again.
A current example is detailed here: https://nick-lucas.github.io/EntryPoint/

Support Lists in Parameters

Right now a standard form list: item1,item2,item3 will be passed back as a string.

If the Tokeniser and Parser can recognise this, then we can populate a List<T> on the ApplicationOptions

Possible Bug: As it stands there is also a strong possibility a list would cause unintended side effects if quotes are used on items.

Add command support

It would be nice if you could write methods which act as entry points for particular commands, ASP.NET Core style.
Take git for example:

git checkout <ref> [-b -f]
git add <path> [-a]

So you could implement it like:

[Route("checkout {ref}")]
public int Checkout(string ref, [Option(ShortName = "b")] bool create, [Option(ShortName = "f", LongName = "force")] bool force)
{
    // code...
}

[Route("checkout {path}")]
public int Add([FromRoute]string path, [Switch('a')] bool all)
{

}

Validate user input for unknown commands/arguments before other validations

Currently if we have a default command, and the user mis-types a command name, the default will take control and be passed the broken command as the first argument.

We can then end up in a situation where the wrong command is called, or the correct command is called but in an invalid args state, which causes unclear exceptions to bubble back up that are intended for more specific scenarios.

By validating inputs before throwing any other sort of exception, we can get around this.

.Net string[] args tokenisation behaviour

    /// <summary>
    /// .Net Behaviour Observations
    /// 
    /// .Net automatically tokenises command line arguments and passes them to the program as `string[] args`
    /// 
    /// .Net Core does not provide raw access to the original string due to x-platform concerns, 
    /// see: https://github.com/dotnet/coreclr/issues/3103
    /// This may change in the future
    /// 
    /// .Net tokenisation does a few things:
    /// * Split on Whitespace (Good)
    /// * Protects quoted contiguous text which means: 
    ///     ` "1 23",456 ` transforms to a single token: ` 1 23,456 ` (Good)
    /// * Strips quotes, even on list tokens, which means 
    ///     ` "1,23",456 ` transforms to a single token: ` 1,23,456 ` (BAD)
    /// 
    /// This behaviour needs to be worked with by the Tokeniser.
    /// 
    /// The latter behaviour is un-workable and needs to be communicated as a limitation, 
    /// and communicated to the .Net team
    /// 
    /// </summary>

Don't surface exceptions for UserFacingException

This might be a breaking change, so some sort of option should be provided.

Currently when a subclass of UserFacingException is thrown it bubbles up to the Cli.MethodName call.

It might be a good idea to let developers override this on CliArguments/Commands classes in the same way which the help generator can be overridden, using a virtual method with a common-sense default implementation.

Add default implementation for OnHelpInvoked

It's not totally obvious when first building a CLI that --help is doing nothing because you haven't implemented it.

Would be best to provide a default implementation and advertise it can be overiden, in the docs

Support Mapping of positional Operands

A new attribute could be used to map positional operands much like Options are mapped.

Something like:

[Operand(
    Position = 1, 
    [ParameterDefaultBehaviour], 
    [ParameterDefaultValue])]

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.