mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa3094ee54 | ||
|
|
712580e3d7 | ||
|
|
c08102f85f |
@@ -1,3 +1,7 @@
|
|||||||
|
### v2.2.1 (16-Jan-2022)
|
||||||
|
|
||||||
|
- Fixed an issue which caused help text to not show default values for optional parameters. (Thanks [@AliReZa Sabouri](https://github.com/alirezanet))
|
||||||
|
|
||||||
### v2.2 (11-Jan-2022)
|
### v2.2 (11-Jan-2022)
|
||||||
|
|
||||||
- Added support for optional parameters. A parameter can be marked as optional by setting `IsRequired = false` on the attribute. Only one parameter is allowed to be optional and such parameter must be the last in order. (Thanks [@AliReZa Sabouri](https://github.com/alirezanet))
|
- Added support for optional parameters. A parameter can be marked as optional by setting `IsRequired = false` on the attribute. Only one parameter is allowed to be optional and such parameter must be the last in order. (Thanks [@AliReZa Sabouri](https://github.com/alirezanet))
|
||||||
|
|||||||
@@ -206,6 +206,12 @@ internal class HelpConsoleFormatter : ConsoleFormatter
|
|||||||
Write('.');
|
Write('.');
|
||||||
Write(' ');
|
Write(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default value
|
||||||
|
if (!parameterSchema.IsRequired)
|
||||||
|
{
|
||||||
|
WriteDefaultValue(parameterSchema);
|
||||||
|
}
|
||||||
|
|
||||||
WriteLine();
|
WriteLine();
|
||||||
}
|
}
|
||||||
@@ -298,60 +304,65 @@ internal class HelpConsoleFormatter : ConsoleFormatter
|
|||||||
// Default value
|
// Default value
|
||||||
if (!optionSchema.IsRequired)
|
if (!optionSchema.IsRequired)
|
||||||
{
|
{
|
||||||
var defaultValue = _context.CommandDefaultValues.GetValueOrDefault(optionSchema);
|
WriteDefaultValue(optionSchema);
|
||||||
if (defaultValue is not null)
|
|
||||||
{
|
|
||||||
// Non-Scalar
|
|
||||||
if (defaultValue is not string && defaultValue is IEnumerable defaultValues)
|
|
||||||
{
|
|
||||||
var elementType =
|
|
||||||
defaultValues.GetType().TryGetEnumerableUnderlyingType() ??
|
|
||||||
typeof(object);
|
|
||||||
|
|
||||||
if (elementType.IsToStringOverriden())
|
|
||||||
{
|
|
||||||
Write(ConsoleColor.White, "Default: ");
|
|
||||||
|
|
||||||
var isFirst = true;
|
|
||||||
|
|
||||||
foreach (var element in defaultValues)
|
|
||||||
{
|
|
||||||
if (isFirst)
|
|
||||||
{
|
|
||||||
isFirst = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Write(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
Write('"');
|
|
||||||
Write(element.ToString(CultureInfo.InvariantCulture));
|
|
||||||
Write('"');
|
|
||||||
}
|
|
||||||
|
|
||||||
Write('.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (defaultValue.GetType().IsToStringOverriden())
|
|
||||||
{
|
|
||||||
Write(ConsoleColor.White, "Default: ");
|
|
||||||
|
|
||||||
Write('"');
|
|
||||||
Write(defaultValue.ToString(CultureInfo.InvariantCulture));
|
|
||||||
Write('"');
|
|
||||||
Write('.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLine();
|
WriteLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void WriteDefaultValue(IMemberSchema schema)
|
||||||
|
{
|
||||||
|
var defaultValue = _context.CommandDefaultValues.GetValueOrDefault(schema);
|
||||||
|
if (defaultValue is not null)
|
||||||
|
{
|
||||||
|
// Non-Scalar
|
||||||
|
if (defaultValue is not string && defaultValue is IEnumerable defaultValues)
|
||||||
|
{
|
||||||
|
var elementType =
|
||||||
|
defaultValues.GetType().TryGetEnumerableUnderlyingType() ??
|
||||||
|
typeof(object);
|
||||||
|
|
||||||
|
if (elementType.IsToStringOverriden())
|
||||||
|
{
|
||||||
|
Write(ConsoleColor.White, "Default: ");
|
||||||
|
|
||||||
|
var isFirst = true;
|
||||||
|
|
||||||
|
foreach (var element in defaultValues)
|
||||||
|
{
|
||||||
|
if (isFirst)
|
||||||
|
{
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
Write('"');
|
||||||
|
Write(element.ToString(CultureInfo.InvariantCulture));
|
||||||
|
Write('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
Write('.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (defaultValue.GetType().IsToStringOverriden())
|
||||||
|
{
|
||||||
|
Write(ConsoleColor.White, "Default: ");
|
||||||
|
|
||||||
|
Write('"');
|
||||||
|
Write(defaultValue.ToString(CultureInfo.InvariantCulture));
|
||||||
|
Write('"');
|
||||||
|
Write('.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void WriteCommandChildren()
|
private void WriteCommandChildren()
|
||||||
{
|
{
|
||||||
var childCommandSchemas = _context
|
var childCommandSchemas = _context
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<Project>
|
<Project>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.2</Version>
|
<Version>2.2.1</Version>
|
||||||
<Company>Tyrrrz</Company>
|
<Company>Tyrrrz</Company>
|
||||||
<Copyright>Copyright (C) Alexey Golub</Copyright>
|
<Copyright>Copyright (C) Oleksii Holub</Copyright>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019-2022 Alexey Golub
|
Copyright (c) 2019-2022 Oleksii Holub
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
Reference in New Issue
Block a user