mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Refactor CliApplication
This commit is contained in:
@@ -75,16 +75,21 @@ namespace CliFx
|
||||
// Get parent command schema
|
||||
var parentCommandSchema = availableCommandSchemas.FindParent(commandInput.CommandName);
|
||||
|
||||
// Use a stub if parent command schema is not found
|
||||
if (parentCommandSchema == null)
|
||||
// Show help for parent command if it's defined
|
||||
if (parentCommandSchema != null)
|
||||
{
|
||||
parentCommandSchema = CommandSchema.StubDefaultCommand;
|
||||
availableCommandSchemas = availableCommandSchemas.Concat(new[] { parentCommandSchema }).ToArray();
|
||||
var helpTextSource = new HelpTextSource(_metadata, availableCommandSchemas, parentCommandSchema);
|
||||
_helpTextRenderer.RenderHelpText(_console, helpTextSource);
|
||||
}
|
||||
// Otherwise show help for a stub default command
|
||||
else
|
||||
{
|
||||
var helpTextSource = new HelpTextSource(_metadata,
|
||||
availableCommandSchemas.Concat(CommandSchema.StubDefaultCommand).ToArray(),
|
||||
CommandSchema.StubDefaultCommand);
|
||||
|
||||
// Show help
|
||||
var helpTextSource = new HelpTextSource(_metadata, availableCommandSchemas, parentCommandSchema);
|
||||
_helpTextRenderer.RenderHelpText(_console, helpTextSource);
|
||||
_helpTextRenderer.RenderHelpText(_console, helpTextSource);
|
||||
}
|
||||
|
||||
return isError ? -1 : 0;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,14 @@ namespace CliFx.Internal
|
||||
|
||||
public static IEnumerable<T> ExceptNull<T>(this IEnumerable<T> source) where T : class => source.Where(i => i != null);
|
||||
|
||||
public static IEnumerable<T> Concat<T>(this IEnumerable<T> source, T value)
|
||||
{
|
||||
foreach (var i in source)
|
||||
yield return i;
|
||||
|
||||
yield return value;
|
||||
}
|
||||
|
||||
public static bool Implements(this Type type, Type interfaceType) => type.GetInterfaces().Contains(interfaceType);
|
||||
|
||||
public static Type GetEnumerableUnderlyingType(this Type type)
|
||||
|
||||
Reference in New Issue
Block a user