Comments (8)
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.
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:
from clifx.
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.
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.
You're welcome!
from clifx.
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.
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.
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)
- Add IConsole.Clear()
- Separation of model from business logic HOT 7
- Check `BindingConverter<T>` and `BindingValidator<T>` types in analyzers
- Executable name does not appear in help text in some terminals HOT 4
- How do you wrap help output? HOT 1
- Add multi-language output message support HOT 5
- Command examples HOT 3
- Drop support for targets below net5.0 HOT 11
- Positional arguments listed out-of-order when inheriting from base command class HOT 2
- ConsoleWriter is not thread-safe HOT 1
- `IConsole.ReadKey` should return the key that was read HOT 1
- Support `=` (equal sign) as value separator in argument syntax HOT 4
- Assembly binding confusion results in many AD0001 analyzer warnings HOT 11
- `FakeInMemoryConsole.Clear()` has no effect HOT 4
- Capturing Trace and Debug output HOT 1
- Default `IsRequired` for options based on whether the `required` modifier is used on the property
- CliFx.Analyzers produces hundreds of CS8032 warnings in build HOT 9
- Publishing an exe as "PublishSingleFile=true" with version 2.3.4 fails HOT 2
- Calling commands from other rcommands HOT 3
- Allow the non scalar parameter to be optional or have default value HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clifx.