Giter Site home page Giter Site logo

Comments (8)

stefanjarina avatar stefanjarina commented on May 8, 2024 2

Hi, thanks a lot, Problem 1 pretty much solved.
As for the Problem 2 I guess, that I will just make it absolutely clear in help that it have to be specified at the end of the command and that's it.
Thanks for your help.

from clifx.

Tyrrrz avatar Tyrrrz commented on May 8, 2024 1

Regarding "Problem 1" I would also suggest default interface members feature introduced in C#8 which essentially allows multiple inheritance. You can use that to compose options/parameters in your commands.

Regarding "Problem 2" it's explained a little bit in readme and, to summarize, the answer is readability. With dotnet run -- config -r Github get myKey it's very unclear whether get and myKey are also part of -r or not, and you can only be sure if you know how the tool is implemented. With dotnet run -- config get myKey -r Gitlab it's clear and there's no ambiguity.

Most CLIs that I know are not picky about order and accept options mixed with parameters, so both approaches work. With CliFx the order is enforced for consistency.

Also, dotnet is an example of a CLI where order matters as well:

image

from clifx.

domn1995 avatar domn1995 commented on May 8, 2024

I would solve Problem 1 by using inheritance. Essentially, put all the "global" options in an abstract base class and extend that base class for all your commands.

from clifx.

stefanjarina avatar stefanjarina commented on May 8, 2024

Hello, thank you a lot for answer, abstract class works and it solves Problem 1 that I can use it at the end of command without implementing it in every command.

Works:

-> dotnet run -- config get myKey -r Gitlab

Passed Global Option Repo: 'Gitlab'

Problem 2 however blocks in using it in the middle
Doesn't Work (and it is strange)

-> dotnet run -- config -r Github get myKey

Option --repo|-r expects a single value, but provided with multiple:
"Github" "get" "myKey"
Usage
  dotnet ginit.dll config [command] [options]

Options
  -r|--repo         Specify repository Valid values: "Github", "Gitlab", "Azure", "Bitbucket". Default: "Github".
  -h|--help         Shows help text.

Commands
  get               Get value of a configuration key

You can run `dotnet ginit.dll config [command] --help` to show help on a specific command.

I think it can be solved 2 ways:

1. Allow single

[CommandOption("name", "n", IsSingle = true, ....)] or [CommandOptionSingle("name", "n", ....)]

2. Allow to specify the # of arguments belonging to the option

[CommandOption("name", "n", ArgSize = 2)] or NArgs, NumberOfArguments NumberOfArgs, etc...

example:
python click library have it implemented in this way:

Sometimes, you have options that take more than one argument. For options, only a fixed number of arguments is supported. This can be configured by the nargs parameter. The values are then stored as a tuple.

@click.command()
@click.option('--pos', nargs=2, type=float)
def findme(pos):
    click.echo('%s / %s' % pos)

And on the command line:

$ findme --pos 2.0 3.0
2.0 / 3.0

I think, here might be problematic to pass value to subcommands, so for me it is enough that I can use globals at the end of the commands, however it is strange and people would expect that globals work anywhere in the command.

Once again, thanks.

from clifx.

Tyrrrz avatar Tyrrrz commented on May 8, 2024

You're welcome!

from clifx.

alirezanet avatar alirezanet commented on May 8, 2024

Regarding "Problem 1" I would also suggest default interface members feature introduced in C#8 which essentially allows multiple inheritance. You can use that to compose options/parameters in your commands.

this is a little bit confusing because clifx doesn't recognize default interface members in the commands! what did I miss!? can you explain a little bit?

from clifx.

Tyrrrz avatar Tyrrrz commented on May 8, 2024

Regarding "Problem 1" I would also suggest default interface members feature introduced in C#8 which essentially allows multiple inheritance. You can use that to compose options/parameters in your commands.

this is a little bit confusing because clifx doesn't recognize default interface members in the commands! what did I miss!? can you explain a little bit?

I haven't tried that in a while, what happens exactly? Do default members function differently from inherited members in terms of reflection?

from clifx.

alirezanet avatar alirezanet commented on May 8, 2024

Yes, if you mean something like this

public interface IBaseOptions : ICommand
{
   [CommandOption("no-color", 'c', Description = "Disable color output")]
   public bool NoColor
   {
      get => !Logger.Colors;
      set => Logger.Colors = !value;
   }

   [CommandOption("quite", 'q', Description = "Disable console output")]
   public bool Quite
   {
      get => Logger.Quiet;
      set => Logger.Quiet = value;
   }

   [CommandOption("verbose", 'v', Description = "Enable verbose output")]
   public bool Verbose
   {
      get => Logger.Verbose;
      set => Logger.Verbose = value;
   }
}

public class SomeCommand: IBaseOptions {}

it doesn't work by default. you need explicit type casting first, these props belong to the IBaseOptions type, not SomeCommand
(this could be a great feature though :) )

from clifx.

Related Issues (20)

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.