Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public CommandLineApplication CreateApplication(
            Type type,
            IDependencyResolver dependencyResolver,
            CommandLineApplication parentApplication = null)
        {
            bool isRootApp = parentApplication == null;

            CommandLineApplication app;

            var applicationAttribute = type.GetCustomAttribute <ApplicationMetadataAttribute>(false);

            string appName = applicationAttribute?.Name ?? type.Name.ChangeCase(_appSettings.Case);

            if (isRootApp)
            {
                app = new CommandLineApplication(_appSettings)
                {
                    Name = appName,
                    CustomAttributeProvider = type
                };
                AddVersion(app);
            }
            else
            {
                app = parentApplication.Command(appName);
            }

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

            commandCreator.CreateDefaultCommand(applicationAttribute);

            commandCreator.CreateCommands();

            CreateSubApplications(type, app, dependencyResolver);

            return(app);
        }