GithubHelp home page GithubHelp logo

bilal-fazlani / commanddotnet Goto Github PK

View Code? Open in Web Editor NEW
568.0 568.0 32.0 4.91 MB

A modern framework for building modern CLI apps

Home Page: https://commanddotnet.bilal-fazlani.com

License: MIT License

C# 97.64% Shell 2.35% Batchfile 0.01%
argument-parser command-line console-application csharp dotnet-core

commanddotnet's Introduction

Bilal Fazlani

commanddotnet's People

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

commanddotnet's Issues

Dependency Injection example?

Hi there,

Great library, I was wondering how you could use dependency injection when calling

AppRunner<Calculator> appRunner = new AppRunner<Calculator>();?

I would like to inject a class in my Calculator class how would I go about doing that?

    class Program
    {
        static int Main(string[] args)
        {          
            //  setup our DI
            var services = new ServiceCollection();            
            services.AddTransient<IHelloService, HelloService>();      
            var serviceProvider = services.BuildServiceProvider();
           
            // ---------------------------------------------------
           // Not sure how to use this ??? 
            var app = serviceProvider.GetService<Calculator>();
            //app.Run(args);
            ///------------------------------------------------

            AppRunner<Calculator> appRunner = new AppRunner<Calculator>();
            return appRunner.Run(args);
        }
    }

Example of what I'm trying to implement:
https://github.com/NLog/NLog.Extensions.Logging/wiki/Getting-started-with-.NET-Core-2---Console-application

Support constructor

Constructor should get executed when application is called without any parameters

Call commands from other commands

Great effort with this library, I like the new features you have been implementing

I was wondering how you would go about handling or structuring the following requirement

Say I have 3 commands
Command1, Command2 and All

For my All Command I would like to call Command1 and Command2
Currently I'm able to do this by doing the following:

[DefaultMethod]
public void AllCommand() {
   var command1 = new Command1();
   command1.DoSomethng();
}

While this works, the issue is if Command1 has dependencies IFooService this wouldn't be injected because I'm newing up commmands.

I'm just wondering how you would about structuring such a requirement?

Thanks for your time and effort

Change usage for root app

Hi,

We are running .Net core, and global tools, so we would like to have the option to specify the "Usage:" help text.
Today it's hard coded in AppCreator.cs as: $"dotnet {Assembly.GetEntryAssembly().GetName().Name}.dll";
Would appreciate an option to override this, as the usage is not correct in regards to using global tools.

Best regards

Blocking creating a commanddotnet.ioc.simpleinjector

The ms & autofac ioc extensions reference the internal field AppRunner.DependencyResolver which in turn requires an "[assembly: InternalsVisibleTo("CommandDotNet.IoC.MicrosoftDependencyInjection")]" line. This prevents us from implementation a new ioc tech w/o first getting a PR merged into your master. If enough people adopt this, that class will be littered. Can DependencyResolver be converted to a property with an external setter and a private or internal getter?

PreExecute methods

Hi, I want to say thank you for your library. It deserves many more stars and is just awesome. Almost as good as cobra (go-package)

What I am missing are prehooks and posthooks. My use case:

I have a CLI that connects to a service and all sub commands need to establish a communication with a GRPC service. Would be easier with prehooks: https://github.com/spf13/cobra#prerun-and-postrun-hooks

Issues with 1.1.28 & 2.0.0

Issue 1
dotnet run is showing class name

image

Issue 2
dotnet run stxxxx showing command garbage and showing current command name at the top

image

Type 'Decimal' is not supported'

Just leave this issue here. It was unexpectedly for me that library doesn't support decimal(as type of property in the model). So I hope someone who faced the similar issue can find this issue

Autocomplete feature

Let's try n use this library to provide autocomplete for commands & subcommands first. Then if possible, we can incorporate autocomplete for option names too.

Providing common behavior to wrap execution of a command

Hi @bilal-fazlani ,

We are adding a framework around your framework to encapsulate common use cases for our infrastructure. We'd like a hook that let's us perform some logic before the command method executes.

We were thinking a delegate on CommandRunner with a signature something like....

object OnRun(RunContext)

public class RunContext { Action RunDelegate {get; set;} AppSettings AppSettings {get; set;} CommandInfo CommandInfo {get; set;} List<ArgumentInfo> ParameterValues {get; set;}

This allows us to wrap the execution of the command in our own logic and also gives us enough metadata about the execution to understand the command.

If you approve of this approach, we can submit a PR for it.

Feature request: Place parameters in the middle.

Hi,
I am not sure if it makes sense, but very often I have commands like

cli gateway get-configuration 1A827Ah66
cli gateway add-x 1A827Ah66

The 1A827Ah66 is an id or longer name and when I have to use multiple commands it is annoying to reenter it all the time. Therefore it would be more convenient to have the following syntax:

cli gateway 1A827Ah66 get-configuration 
cli gateway 1A827Ah66 add-x 

So that I only have to replace the last part. Is it somehow possible?

Support for validations

Add support for

  • type validations
  • required valiations
  • error messages on validation failures
  • appropriate return codes

Issues with 1.1.14

Hi there,

Thanks for getting 1.1.14 up, I've done a bit of testing with it and noticed the following issues:

Issue 1 - Commands not lower cased when using [ApplicationMetadata(Name =]
I noticed a minor issue with casing

I have defined my application such as:

AppRunner<FooApplication> appRunner = 
new AppRunner<FooApplication>(new CommandDotNet.Models.AppSettings { Case = Case.LowerCase})
.UseMicrosoftDependencyInjection(serviceProvider);

I have defined my command as follows:
[ApplicationMetadata(Name = "Info",

The command still shows up as Info instead of info

Issue 2 - Version number being printed"
I noticed the version number is being printed when run my application dotnet run. Perhaps it was left for debugging purposes?
image

Issue 3 - Help commands not showing correctly

    [ApplicationMetadata(Name = "Foo", Description = "Foo Service")]
    public class FooCommand
    {
        [ApplicationMetadata(Name = "Hello", Description = "Hello Service")]
        public async Task<bool> Download([Option]string provider = "abc")
        {

image

Alias & text matching for commands

  • Support alias for commands
  • Support for string matching for commands

text matching similar to:

    git: 'puhs' is not a git command. See 'git --help'
    
    Did you mean this?
          push

Model support - composing objects to reuse common arguments

In cases where you want ubiquitous arguments (--dryrun, --verbose, --fail-fast, --customer) it would be great to define those only once so we don't have to redefine them for each command. I didn't see a way to do this.

If there isn't a way to do it, I was thinking that with the Model support you've added, if a property of the IArgumentModel class was also of type IArgumentModel, then the framework could create an instance and map those arguments as well.

What do you think?

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.