internal static string GetAppName(this Command command, AppHelpSettings appHelpSettings)
        {
            if (!appHelpSettings.UsageAppName.IsNullOrEmpty())
            {
                return(appHelpSettings.UsageAppName);
            }

            switch (appHelpSettings.UsageAppNameStyle)
            {
            case UsageAppNameStyle.Adaptive:
                return(GetAppNameAdaptive());

            case UsageAppNameStyle.DotNet:
                return($"dotnet {GetAppFileName()}");

            case UsageAppNameStyle.GlobalTool:
                var rootAppName = GetRootAppName(command);
                if (rootAppName == null)
                {
                    throw new AppRunnerException(
                              $"Invalid configuration: {nameof(CommandAttribute)}.{nameof(CommandAttribute.Name)} " +
                              $"is required for the root command when {nameof(UsageAppNameStyle)}.{nameof(UsageAppNameStyle.GlobalTool)} " +
                              "is specified.");
                }
                return(rootAppName);

            case UsageAppNameStyle.Executable:
                return(GetAppFileName());

            default:
                throw new ArgumentOutOfRangeException(nameof(UsageAppNameStyle), $"unknown style: {appHelpSettings.UsageAppNameStyle}");
            }
        }
示例#2
0
        internal static string GetAppName(this Command command, AppHelpSettings appHelpSettings)
        {
            if (!appHelpSettings.UsageAppName.IsNullOrEmpty())
            {
                return(appHelpSettings.UsageAppName !);
            }

            switch (appHelpSettings.UsageAppNameStyle)
            {
            case UsageAppNameStyle.Adaptive:
                var appInfo = AppInfo.Instance;
                return(appInfo.IsRunViaDotNetExe
                        ? $"dotnet {appInfo.FileName}"
                        : appInfo.FileName);

            case UsageAppNameStyle.DotNet:
                return($"dotnet {AppInfo.Instance.FileName}");

            case UsageAppNameStyle.Executable:
                return(AppInfo.Instance.FileName);

            default:
                throw new ArgumentOutOfRangeException(nameof(UsageAppNameStyle), $"unknown style: {appHelpSettings.UsageAppNameStyle}");
            }
        }
        internal static string GetAppName(this Command command, AppHelpSettings appHelpSettings)
        {
            if (!appHelpSettings.UsageAppName.IsNullOrEmpty())
            {
                return(appHelpSettings.UsageAppName);
            }

            switch (appHelpSettings.UsageAppNameStyle)
            {
            case UsageAppNameStyle.Adaptive:
                var appInfo = AppInfo.Instance;
                return(appInfo.IsRunViaDotNetExe
                        ? $"dotnet {appInfo.FileName}"
                        : appInfo.FileName);

            case UsageAppNameStyle.DotNet:
                return($"dotnet {AppInfo.Instance.FileName}");

            case UsageAppNameStyle.GlobalTool:
                var rootAppName = command.GetRootCommand()
                                  .GetCustomAttribute <CommandAttribute>()?
                                  .Name;
                if (rootAppName == null)
                {
                    throw new AppRunnerException(
                              $"Invalid configuration: {nameof(CommandAttribute)}.{nameof(CommandAttribute.Name)} " +
                              $"is required for the root command when {nameof(UsageAppNameStyle)}.{nameof(UsageAppNameStyle.GlobalTool)} " +
                              $"is specified.{Environment.NewLine}" +
                              $"Use {nameof(AppSettings)}.{nameof(AppSettings.Help)}.{nameof(AppHelpSettings.UsageAppName)} " +
                              $"instead of {nameof(UsageAppNameStyle)}.{nameof(UsageAppNameStyle.GlobalTool)}.");
                }
                return(rootAppName);

            case UsageAppNameStyle.Executable:
                return(AppInfo.Instance.FileName);

            default:
                throw new ArgumentOutOfRangeException(nameof(UsageAppNameStyle), $"unknown style: {appHelpSettings.UsageAppNameStyle}");
            }
        }
 public HelpTextProvider(AppSettings appSettings, string appName = null)
 {
     _appSettings     = appSettings;
     _appName         = appName;
     _appHelpSettings = appSettings.Help;
 }
 public HelpTextProvider(AppSettings appSettings, string?appName = null)
 {
     _appName         = appName;
     _appHelpSettings = appSettings.Help;
     _localize        = appSettings.Localize ?? (s => s);
 }