Commit Graph

44 Commits

Author SHA1 Message Date
67c3909bbb Add support for required options 2025-05-25 16:42:43 +02:00
958820dd66 Tighten up when to show/hide the application "-v|--version" option. 2025-04-08 16:53:43 +02:00
e9f9f56189 Check if the command has a version option on its setting class 2025-04-08 16:43:49 +02:00
dfdd129dd0 Display the application version (if set) when a version flag is the first argument, even if a default command has been set. 2025-04-08 16:43:49 +02:00
520efe07e2 Significant improvement to the command line parsing 2025-04-08 16:38:37 +02:00
93668e92b6 Changed IConfigurator to return IConfigurator instead of void for (#1762) 2025-02-24 20:57:23 +00:00
5c87d7fa04 Allow using -? as a shorthand for -h
Given that it's quite a common switch and extremely unlikely to be already in use for something else, we can just consider it to be the same as having entered `-h` as an arg.

This adds the `?` as a valid option character name.

Fixes #1547
2024-05-29 08:38:55 +02:00
b1b50a21f7 Remove redundant explain settings ctor 2024-04-27 07:41:08 +02:00
3acc90e47c Make -v|--version opt-in
We added an automatic version option in 0.49. We did this with good
intentions, but forgot that people might already use --version
as an option for a root command.

This commit makes -v|--version completely opt-in.
2024-04-25 20:28:13 +02:00
71f762f646 Add token representation to remaining arguments
Before, when adding parsed information to the IRemainingArguments.Parsed,
we used the name of the parsed option ('foo') instead of it's
representation ('--foo'). This commit fixes that.
2024-04-23 14:10:04 +02:00
95bff47b85 Expose raw arguments on the command context 2024-04-20 22:17:31 +02:00
1a3249cdae Improve XmlDoc output (#1503)
* Add command description and examples in XML Output

Closes #1115
2024-03-29 20:30:59 +01:00
43f9ae92ad Pipe character for listing options - Fully implemented and tested. 2024-03-18 16:31:55 +01:00
fde9ee04cf Automatically register command settings
Closes #428
2024-02-15 21:33:51 +01:00
9cc888e5ad Make HelpProvider colors configurable (#1408) 2024-01-18 15:31:28 +01:00
cee97821d6 Fix stylecop warning 2024-01-15 19:22:34 +01:00
55c763a5c2 Completed 2024-01-15 19:22:34 +01:00
544e6a92df Added the ITypeResolver to the ExceptionHandler (#1411) 2024-01-06 23:34:02 +00:00
a94bc15746 Add the possibility to register multiple interceptors (#1412)
Having the interceptors registered with the ITypeRegistrar also enables the usage of ITypeResolver in interceptors.
2024-01-06 22:28:20 +00:00
44300c871f fixed line-endings 2023-11-28 00:14:54 +01:00
250b1f4c9c Add localization support to help provider (#1349)
Closes #1349
2023-11-11 00:22:52 +01:00
3da367f29f (#1313) fix mixing of Registrations
i.e. combining Register, RegisterInstance and RegisterLazy
2023-11-11 00:09:08 +01:00
1fd028942f (#1313) removed the default registration of the IHelpProvider 2023-11-11 00:09:08 +01:00
5296e56b1c Fix DefaultValue for FileInfo and DirectoryInfo (#1238)
Commit d3f4f5f208 introduced automatic conversion to FileInfo and DirectoryInfo but failed to properly handle the conversion if the value comes from the [DefaultValue] attribute.

Using both `var (converter, stringConstructor) = GetConverter(...)` and `var (converter, _) = GetConverter(...)` should have been a red flag!
2023-09-21 12:05:42 +01:00
131b37fff8 Allow custom help providers (#1259)
Allow custom help providers

* Version option will show in help even with a default command

* Reserve `-v` and `--version` as special Spectre.Console command line arguments (nb. breaking change for Spectre.Console users who have a default command with a settings class that uses either of these switches).

* Help writer correctly determines if trailing commands exist and whether to display them as optional or mandatory in the usage statement.

* Ability to control the number of indirect commands to display in the help text when the command itself doesn't have any examples of its own. Defaults to 5 (for backward compatibility) but can be set to any integer or zero to disable completely.

* Significant increase in unit test coverage for the help writer.

* Minor grammatical improvements to website documentation.
2023-09-08 09:51:33 +02:00
2af901a814 Remove unnecessary [NotNull] attributes
When subclassing `Command<TSettings>` which has the [NotNull] attributes, Rider/ReSharper gives this warning:
> Nullability of type of parameter 'context' in method does not match overridden member `int Spectre.Console.Cli.Command<TSettings>.Execute(CommandContext, TSettings)` (possibly because of nullability attributes)

When subclassing `Command<TSettings>` which does not have the [NotNull] attributes, Rider/ReSharper gives this warning:
> The nullability attribute has no effect and can be safely removed

The solution is simply to remove the [NotNull] attributes.

Since `<Nullable>enable</Nullable>` is set in the project, they are actually not necessary. By the way, the non-generic `Command` class does not have the [NotNull] attributes.
2023-07-12 15:26:12 +02:00
35ce60b596 Implemented AddAsyncDelegate (#766) 2023-05-25 11:31:01 +01:00
404b052a5f Add ability to pass example args using params syntax (#1166) 2023-05-12 12:08:42 +01:00
dac2097321 Add support for arrays in [DefaultValue] attributes (#1164)
Fixes #1163
2023-05-11 14:26:53 +01:00
714cf179cb Command line improvements (#1103)
Closes #187
Closes #203
Closes #1059
2023-04-02 22:43:21 +02:00
d3f4f5f208 Add support for converting command parameters into FileInfo and DirectoryInfo (#1145)
Add support for converting command parameters that doesn't have a built-in TypeConverter but has a constructor that takes a string. For CLI apps, FileInfo and DirectoryInfo will likely be the most useful ones, but there may be others.
2023-03-01 12:02:43 +00:00
04610cf492 Alias for command branches (#411) 2023-02-09 14:26:06 +00:00
de847b90e4 Improve conversion error messages
When a conversion to an enum fails, list all the valid enum values in the error message.

Message before this commit:
> Error: heimday is not a valid value for DayOfWeek.

Message after this commit:
> Error: Failed to convert 'heimday' to DayOfWeek. Valid values are 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
2023-01-24 19:40:11 +01:00
7b9553dd22 Add possibility to set description and/or data for the default command (#1091) 2023-01-12 12:12:27 +00:00
3e6e0990c5 Automatically display default values of options in the help page (#1032)
Fixes #973
2022-12-28 20:28:41 +00:00
4a8a4ab048 Show help for default command (#953)
Shows help if the default command was called without any arguments but has required arguments.
This way it does not hinder execution of a default command without any required arguments.

When called without args:
- Default command with required params -> Show help
- Default command with required params and additional commands -> Show help including additional commands
- Default command without required params -> Execute command
2022-12-14 17:19:12 +00:00
b793482ebb Command line argument parsing improvements (#1048)
* Support negative numbers as command option values
* Support command line options before arguments
* POSIX-compliant handling of quotes (double and single, terminated and unterminated), whitespace, hyphens, and special characters (e.g. emojis)
2022-12-05 01:07:53 +01:00
c3ec6a7363 Add Layout widget (#1041)
* Add width to panels
* Add height to panels
* Replace RenderContext with RenderOptions
* Remove exclusivity from alternative buffer
* Add Layout widget
* Add Align widget
2022-11-15 10:12:17 +01:00
a70cc90797 Fix issues with nullability and netstandard2.0 2022-11-10 12:01:13 +01:00
f6a7c96413 Create Test, allow for conditional trim 2022-10-13 20:42:23 +02:00
a91a3c12ad Remove trimming 2022-10-13 20:42:23 +02:00
0d19ccd8a6 (#916) fixed missing call to Validate when using CommandConstructorBinder 2022-08-18 12:03:11 +02:00
78d841e3dc Added command description to command help message (#920) 2022-08-17 16:59:08 +02:00
36ca22ffac Move Spectre.Console.Cli to it's own package 2022-05-15 00:09:52 +02:00