Beispiel #1
0
        public CommandInfo(MethodInfo methodInfo, AppSettings settings)
        {
            _methodInfo = methodInfo;
            _settings   = settings;

            _metadataAttribute = _methodInfo.GetCustomAttribute <ApplicationMetadataAttribute>(false);

            Arguments = new ArgumentInfoCreator(settings).GetArgumentsFromMethod(methodInfo);
        }
Beispiel #2
0
        public CommandLineApplication CreateApplication(
            Type type,
            IDependencyResolver dependencyResolver,
            CommandLineApplication parentApplication = null)
        {
            bool isRootApp = parentApplication == null;

            CommandLineApplication app;

            ApplicationMetadataAttribute consoleApplicationAttribute = type.GetCustomAttribute <ApplicationMetadataAttribute>(false);

            if (isRootApp)
            {
                string assemblyName       = $"{Assembly.GetEntryAssembly().GetName().Name}.dll";
                string defaultRootCommand = $"dotnet {assemblyName}";
                string rootCommandName    = consoleApplicationAttribute?.Name ?? defaultRootCommand;
                app = new CommandLineApplication(_appSettings)
                {
                    Name = rootCommandName
                };
                app.FullName = consoleApplicationAttribute?.Name ?? assemblyName;
                AddVersion(app);
            }
            else
            {
                string appName = consoleApplicationAttribute?.Name ?? type.Name.ChangeCase(_appSettings.Case);
                app = parentApplication.Command(appName, application => { }, _appSettings.HelpTextStyle, _appSettings.ThrowOnUnexpectedArgument);
            }

            app.HelpOption(Constants.HelpTemplate);

            app.Description = consoleApplicationAttribute?.Description;

            app.ExtendedHelpText = consoleApplicationAttribute?.ExtendedHelpText;

            app.Syntax = consoleApplicationAttribute?.Syntax;

            CommandCreator commandCreator = new CommandCreator(type, app, dependencyResolver, _appSettings);

            commandCreator.CreateDefaultCommand();

            commandCreator.CreateCommands();

            CreateSubApplications(type, app, dependencyResolver);

            return(app);
        }