public GetPerforceChanges()
 {
     this.commandLineParser = new CommandLineParser();
     this.processWrapper    = new ProcessWrapper();
     this.changesParser     = new ChangesParser();
     this.cmdlet            = new CmdletAdapter(this);
 }
Exemple #2
0
 public Settings(
     [NotNull] ICommandLineParser commandLineParser,
     [NotNull] Func <ILog <Settings> > log)
 {
     _commandLineParser = commandLineParser ?? throw new ArgumentNullException(nameof(commandLineParser));
     _log = log ?? throw new ArgumentNullException(nameof(log));
 }
Exemple #3
0
 public GetGitLog()
 {
     this.commandLineParser = new CommandLineParser();
     this.processWrapper    = new ProcessWrapper();
     this.gitLogParser      = new GitLogParser();
     this.cmdlet            = new CmdletAdapter(this);
 }
        public void PositionalArguments(
            string[] args,
            string firstParsedArgument,
            string secondParsedArgument,
            ICommandLineParser parser)
        {
            const string FirstArgument  = "firstArgument";
            const string SecondArgument = "secondArgument";

            "establish positional arguments".x(() =>
                                               args = new[]
            {
                FirstArgument, SecondArgument
            });

            "establish a parser with parsing configuration for positional arguments".x(() =>
            {
                parser = new CommandLineParser(CommandLineParserConfigurator
                                               .Create()
                                               .WithPositional(v => firstParsedArgument  = v)
                                               .WithPositional(v => secondParsedArgument = v)
                                               .BuildConfiguration());
            });

            "when parsing".x(() =>
                             parser.Parse(args));

            "should parse positional argument".x(() =>
                                                 new[]
            {
                firstParsedArgument, secondParsedArgument
            }
                                                 .Should().Equal(FirstArgument, SecondArgument));
        }
Exemple #5
0
        private WindowsService(bool interactive, IServiceWrapper wrapper, ILogger logger,
            ICommandLineParser parser, IConsoleHarness console, IAssembly assembly, 
            ServiceAttributeReader reader, WindowsServiceManager manager, HostFactory hostFactory)
        {
            Logger = logger;
            _metadata = reader.GetMetadata(this);

            _interactive = interactive;
            _assembly = assembly;
            Console = console;
            _manager = manager;
            _manager.SetMetadata(_metadata);
            _hostFactory = hostFactory;

            CommandLineParser = parser
                .SetApplicationName(reader.GetAttribute(this).DisplayName)
                .SetDescription(reader.GetAttribute(this).Description)
                .AddOption("quiet", "q", "Enable quiet mode. Will display only errors on the console.",
                    noArgs => _metadata.Quiet = true)
                .AddOption("silent", "si", "Enable silent mode. Will display nothing (not even errors) on the console.",
                    noArgs => _metadata.Silent = true)
                .AddOption("logtoconsole", "l", "Instructs the installer/uninstaller to log the output to the console.",
                    noArgs => _manager.LogToConsole = true)
                .AddOption("debug", "d", "Pauses to attach a debugger.", noArgs => EnableDebugMode())
                .AddOption("uninstall", "u", "Uninstalls the service.", noArgs => _manager.Uninstall())
                .AddOption("install", "i", "Installs the service.", noArgs => _manager.Install())
                .AddOption("installandstart", "is", "Installs and then starts the service.",
                    noArgs => _manager.InstallAndStart())
                .AddOption("start", "s", "Starts the service.", noArgs => _manager.StartService())
                .AddOption("stop", "x", "Stops the service.", noArgs => _manager.StopService())
                .AddOption("status", "st", "Displays the status of the service.", noArgs => _manager.ShowStatus());

            Harness = wrapper.WrapService(this);
        }
        public void RequiredPositional(
            string[] args,
            string firstParsedArgument,
            string secondParsedArgument,
            ICommandLineParser parser,
            ParseResult result)
        {
            const string FirstName   = "firstName";
            const string FirstValue  = "firstValue";
            const string SecondName  = "secondName";
            const string SecondValue = "secondValue";

            "establish some arguments with missing required positional argument".x(() =>
                                                                                   args = new[]
            {
                "-" + FirstName, FirstValue, "-" + SecondName, SecondValue
            });

            "establish a parser with parsing configuration with required positional arguments".x(() =>
            {
                parser = new CommandLineParser(CommandLineParserConfigurator
                                               .Create()
                                               .WithPositional(v => { })
                                               .Required()
                                               .WithNamed(FirstName, v => { })
                                               .WithNamed(SecondName, v => { })
                                               .BuildConfiguration());
            });

            "when parsing".x(() =>
                             result = parser.Parse(args));

            "should return parsing failure".x(() =>
                                              result.Succeeded.Should().BeFalse());
        }
 public void InjectDependencies(ICmdlet cmdlet, IProcessWrapper processWrapper, ICommandLineParser commandLineParser, ILogger logger)
 {
     this.cmdLet            = cmdlet;
     this.processWrapper    = processWrapper;
     this.commandLineParser = commandLineParser;
     this.logger            = logger;
 }
        public void ValueConvertion(
            string[] args,
            int firstParsedArgument,
            bool secondParsedArgument,
            ICommandLineParser parser)
        {
            const int Value = 42;

            "establish non-string arguments".x(() =>
                                               args = new[]
            {
                "-value", Value.ToString(), "true"
            });

            "establish a parser with parsing configuration with type convertion".x(() =>
            {
                parser = new CommandLineParser(CommandLineParserConfigurator
                                               .Create()
                                               .WithNamed("value", (int v) => firstParsedArgument = v)
                                               .WithPositional((bool v) => secondParsedArgument   = v)
                                               .BuildConfiguration());
            });

            "when parsing".x(() =>
                             parser.Parse(args));

            "should convert parsed named arguments".x(() =>
                                                      firstParsedArgument.Should().Be(Value));

            "should convert parsed positional arguments".x(() =>
                                                           secondParsedArgument.Should().BeTrue());
        }
        public void SupportsLongAliasForSwitch(
            string[] args,
            bool firstParsedSwitch,
            string secondParsedSwitch,
            ICommandLineParser parser)
        {
            "establish arguments with switch with long alias".x(() =>
                                                                args = new[]
            {
                "-f", "--secondSwitch"
            });

            "establish a parser with parsing configuration for switches with long aliases".x(() =>
            {
                parser = new CommandLineParser(CommandLineParserConfigurator
                                               .Create()
                                               .WithSwitch("f", () => firstParsedSwitch = true)
                                               .HavingLongAlias("firstSwitch")
                                               .WithSwitch("s", () => secondParsedSwitch = "yeah")
                                               .HavingLongAlias("secondSwitch")
                                               .BuildConfiguration());
            });

            "when parsing".x(() =>
                             parser.Parse(args));

            "should parse switch".x(() =>
                                    new object[]
            {
                firstParsedSwitch, secondParsedSwitch
            }
                                    .Should().Equal(true, "yeah"));
        }
 public StartProcessSync()
 {
     this.cmdLet            = new CmdletAdapter(this);
     this.processWrapper    = new ProcessWrapper();
     this.commandLineParser = new CommandLineParser();
     this.logger            = new RawConsoleLogger();
 }
        public void SupportsRestrictedValues(
            string value,
            string expectedParsedValue,
            bool expectedSuccessful,
            string[] args,
            string parsedValue,
            ICommandLineParser parser,
            ParseResult parseResult)
        {
            "establish arguments".x(() =>
                                    args = new[]
            {
                "-n", value
            });

            "establish a parser with parsing configuration with value check".x(() =>
            {
                parser = new CommandLineParser(CommandLineParserConfigurator
                                               .Create()
                                               .WithNamed("n", v => parsedValue = v)
                                               .RestrictedTo(KnownValue)
                                               .BuildConfiguration());
            });

            "when parsing".x(() =>
                             parseResult = parser.Parse(args));

            "should parse allowed values".x(() =>
                                            parsedValue.Should().Be(expectedParsedValue));

            "should fail for not allowed values".x(() =>
                                                   parseResult.Succeeded.Should().Be(expectedSuccessful));
        }
        public void Switch(
            string[] args,
            bool firstParsedSwitch,
            string secondParsedSwitch,
            ICommandLineParser parser)
        {
            "establish arguments with switch".x(() =>
                                                args = new[]
            {
                "-firstSwitch", "-secondSwitch"
            });

            "establish a parser with parsing configuration for switches".x(() =>
            {
                CommandLineConfiguration configuration = CommandLineParserConfigurator
                                                         .Create()
                                                         .WithSwitch("firstSwitch", () => firstParsedSwitch   = true)
                                                         .WithSwitch("secondSwitch", () => secondParsedSwitch = "yeah")
                                                         .BuildConfiguration();

                parser = new CommandLineParser(configuration);
            });

            "when parsing".x(() =>
                             parser.Parse(args));

            "should parse switch".x(() =>
                                    new object[]
            {
                firstParsedSwitch, secondParsedSwitch
            }
                                    .Should().Equal(true, "yeah"));
        }
Exemple #13
0
        public bool TryParseUnknownCommandArg(string arg, ICommandLineParser parser, out ICommandLineCommand command)
        {
            command = null;

            if (parser.IsSwitch(arg))
            {
                var parameter = arg.Substring(1);
                switch (parameter.ToLowerInvariant())
                {
                case "?":
                case "h":
                case "help":
                    command = new HelpCommand(this.extensions);
                    return(true);
                }
            }

            foreach (var heatExtension in this.extensions)
            {
                if (heatExtension.CommandLineTypes.Any(o => o.Option == arg))
                {
                    command = new HeatCommand(arg, this.extensions, this.serviceProvider);
                    return(true);
                }
            }

            return(false);
        }
Exemple #14
0
        /// <summary>
        /// Extensions to configure FluentValidations for the Parser
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parser"></param>
        /// <param name="configAction">Configuration action</param>
        public static void UseFluentValidations <T>(this ICommandLineParser <T> parser, Action <FluentValidationConfiguration> configAction)
            where T : class, new()
        {
            var config = new FluentValidationConfiguration(parser.Validators, parser.Services);

            configAction(config);
        }
        public ApplicationRunner(ICommandLineParser commandLineParser, ITaskieServiceLocator taskieServiceLocator, ITaskieApplication taskieApplication)
        {
            _commandLineParser = commandLineParser;

            _taskieApplication = getInstanceFromServiceLocator(taskieServiceLocator) ?? taskieApplication;
            _taskieApplication.Startup();
        }
 public void InjectDependencies(IDescribeParser describeParser, IProcessWrapper processWrapper, ICommandLineParser commandLineParser,
                                ICmdlet cmdlet)
 {
     this.processWrapper    = processWrapper;
     this.describeParser    = describeParser;
     this.commandLineParser = commandLineParser;
     this.cmdlet            = cmdlet;
 }
 public GetPerforceChangeset()
 {
     this.processWrapper    = new ProcessWrapper();
     this.describeParser    = new DescribeParser();
     this.commandLineParser = new CommandLineParser();
     this.cmdlet            = new CmdletAdapter(this);
     this.DescribeCommand   = "p4 describe -ds {0}";
 }
Exemple #18
0
 public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper,
                                IGitLogParser gitLogParser, ICmdlet cmdlet)
 {
     this.commandLineParser = commandLineParser;
     this.processWrapper    = processWrapper;
     this.gitLogParser      = gitLogParser;
     this.cmdlet            = cmdlet;
 }
 public void InjectDependencies(ICommandLineParser commandLineParser, IProcessWrapper processWrapper,
                                IChangesParser changesParser, ICmdlet cmdlet)
 {
     this.commandLineParser = commandLineParser;
     this.processWrapper    = processWrapper;
     this.changesParser     = changesParser;
     this.cmdlet            = cmdlet;
 }
		public TerminalCommandExecutor(ITerminal terminal, ICommandLineParser parser)
		{
			if(terminal == null)
				throw new ArgumentNullException("terminal");

			_terminal = terminal;
			this.Parser = parser;
		}
Exemple #21
0
        public Factory(string[] args)
        {
            var wrapper = create_wrapper();

            CmdParser = create_cmd_parser(args);
            Device    = create_device(CmdParser, create_device_reader(wrapper), create_device_sorter(wrapper), create_device_changer(wrapper));
            Menu      = create_menu(Device);
        }
Exemple #22
0
        public static object ParseObject(this ICommandLineParser parser, Type type, Options options, string[] args, bool stopAtNotOption)
        {
            var commandLine = parser.Parse(options, args, stopAtNotOption);
            var obj         = Activator.CreateInstance(type, true);

            ReflectedOptions.SetToObject(options, commandLine, obj);
            return(obj);
        }
        public void Setup()
        {
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);
            var semanticModel = new EmptySemanticModel();

            _parser = new CommandLineParser(lexer, semanticModel, syntaxFactory);
        }
Exemple #24
0
            public bool TryParseArgument(string arg, ICommandLineParser parser)
            {
                if (parser.IsSwitch(arg))
                {
                    var parameter = arg.Substring(1);
                    switch (parameter.ToLowerInvariant())
                    {
                    case "?":
                    case "h":
                    case "help":
                        this.ShowHelp = true;
                        return(true);

                    case "intermediatefolder":
                        this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg);
                        return(true);

                    case "o":
                    case "out":
                        this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "nologo":
                        this.ShowLogo = false;
                        return(true);

                    case "v":
                    case "verbose":
                        this.Messaging.ShowVerboseMessages = true;
                        return(true);

                    case "sw":
                    case "suppresswarning":
                        var warning = parser.GetNextArgumentOrError(arg);
                        if (!String.IsNullOrEmpty(warning))
                        {
                            var warningNumber = Convert.ToInt32(warning);
                            this.Messaging.SuppressWarningMessage(warningNumber);
                        }
                        return(true);
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(this.DecompileFilePath))
                    {
                        this.DecompileFilePath = parser.GetArgumentAsFilePathOrError(arg, "decompile file");
                        return(true);
                    }
                    else if (String.IsNullOrEmpty(this.OutputFile))
                    {
                        this.OutputFile = parser.GetArgumentAsFilePathOrError(arg, "output file");
                        return(true);
                    }
                }

                return(false);
            }
Exemple #25
0
 public GeneralExecutor(
     ICommandLineParser parser,
     IIndex <Verb, IVerbRunnerFactory> factorySelector,
     ILogger <GeneralExecutor> log)
 {
     _parser          = parser;
     _factorySelector = factorySelector;
     _log             = log;
 }
Exemple #26
0
 public Device(ICommandLineParser parser, IDeviceReader deviceReader, IDeviceSorter deviceSorter, IDeviceChanger deviceChanger)
 {
     //TODO OWN Factory pls
     CmdParser = Required.NotNull(parser, nameof(parser));
     _reader   = Required.NotNull(deviceReader, nameof(deviceReader));
     _sorter   = Required.NotNull(deviceSorter, nameof(deviceSorter));
     _changer  = Required.NotNull(deviceChanger, nameof(deviceChanger));
     init_modules();
 }
Exemple #27
0
        private bool TryParseUnknownCommandArg(string arg, ICommandLineParser parser, out ICommandLineCommand command, IEnumerable <IExtensionCommandLine> extensions)
        {
            command = null;

            if (parser.IsSwitch(arg))
            {
                var parameter = arg.Substring(1);
                switch (parameter.ToLowerInvariant())
                {
                case "?":
                case "h":
                case "help":
                    command = new HelpCommand();
                    break;

                case "version":
                case "-version":
                    command = new VersionCommand();
                    break;
                }
            }
            else
            {
                if (Enum.TryParse(arg, true, out CommandTypes commandType))
                {
                    switch (commandType)
                    {
                    case CommandTypes.Build:
                        command = new BuildCommand(this.ServiceProvider);
                        break;

                    case CommandTypes.Compile:
                        command = new CompileCommand(this.ServiceProvider);
                        break;

                    case CommandTypes.Decompile:
                        command = new DecompileCommand(this.ServiceProvider);
                        break;
                    }
                }
                else
                {
                    foreach (var extension in extensions)
                    {
                        if (extension.TryParseCommand(parser, out command))
                        {
                            break;
                        }

                        command = null;
                    }
                }
            }

            return(command != null);
        }
        public TerminalCommandExecutor(ITerminal terminal, ICommandLineParser parser)
        {
            if (terminal == null)
            {
                throw new ArgumentNullException("terminal");
            }

            _terminal   = terminal;
            this.Parser = parser;
        }
Exemple #29
0
        public bool TryParseArgument(ICommandLineParser parser, string argument)
        {
            if (parser.IsSwitch(argument) && argument.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase))
            {
                this.exampleValueFromCommandLine = parser.GetNextArgumentOrError(argument);
                return(true);
            }

            return(false);
        }
            protected override void infrastructure_setup()
            {
                A.CallTo(() => _fakeTaskResolver.GetAllRunnableTasks()).ReturnsEnumerableContaining(new TaskInformation
                                                                                                        {
                                                                                                            Name = _runnableTaskName,
                                                                                                            Description = _runnableTaskDescription
                                                                                                        });

                _commandLineParser = new CommandLineParser(_fakeScreenIO, _fakeTaskResolver);
            }
Exemple #31
0
 public AppController(IFileSystem fileSystem,
                      IConsole consoleAdapter,
                      ICommandLineParser commandLineParser,
                      IExcludeFileParser excludeFileParser)
 {
     _fileSystem        = fileSystem;
     _consoleAdapter    = consoleAdapter;
     _commandLineParser = commandLineParser;
     _excludeFileParser = excludeFileParser;
 }
Exemple #32
0
        public static IEnumerable <string> GetHelp(this ICommandLineParser commandLineParser, IContext targetContext)
        {
            Argument.IsNotNull(() => commandLineParser);

            var dependencyResolver = commandLineParser.GetDependencyResolver();

            var helpWriterService = dependencyResolver.Resolve <IHelpWriterService>();

            return(helpWriterService.GetHelp(targetContext));
        }
Exemple #33
0
        public GitCodeChurnProcessor(ICommandLineParser commandLineParser, IProcessWrapper processWrapper, IGitLogParser gitLogParser, IOutputProcessor outputProcessor, IBugDatabaseProcessor bugDatabaseProcessor, ILogger logger, GitExtractCommandLineArgs commandLineArgs) : this(commandLineParser, processWrapper, gitLogParser, outputProcessor, bugDatabaseProcessor, logger, commandLineArgs.OutputFile, commandLineArgs.OutputType, commandLineArgs.BugRegexes, commandLineArgs.BugDatabaseDLL, commandLineArgs.BugDatabaseOutputFile, commandLineArgs.BugDatabaseDllArgs, commandLineArgs.GitLogCommand)
        {
            if (string.IsNullOrWhiteSpace(bugDatabaseDLL) == false && string.IsNullOrWhiteSpace(bugDatabaseOutputFile))
            {
                throw new Exception("Dll specified without known output file");
            }

            this.bugDatabaseOutputFile = commandLineArgs.BugDatabaseOutputFile;
            this.bugDatabaseOutputType = commandLineArgs.BugDatabaseOutputType;
        }
Exemple #34
0
        public CommandLineSyntaxHighlighter(
            ICommandLineParser parser,
            CommandLineHighlightingOptions highlightingOptions = null)
        {
            _parser = parser ?? throw new ArgumentNullException(nameof(parser));
            _highlightingOptions = highlightingOptions ?? new CommandLineHighlightingOptions();
            _highlightingOptions.Validate();

            _highlightingVisitor = new CommandLineHighlightingVisitor <TextStyle>();
        }
 public NotificationConfigurationService(ICommandLineParser commandLineParser)
 {
     this.commandLineParser = commandLineParser;
 }
Exemple #36
0
        public void HandleCommandLine(string [] args, ICommandLineParser parser)
        {
            if (parser == null)
                throw new ArgumentNullException("parser");

            Initialize();

            parser.Options = appOptions;
            CommandLine commandLine = parser.Parse(args);
            if (commandLine.HasParsed)
                HandleCommandLine(commandLine);
        }
        public void SetUp()
        {
            options = new Options().AddOption("p", false, "Option p").AddOption("attr", true, "Option accepts argument");

            parser = new PosixParser();
        }
        public void InitializeTest()
        {
            // Create fake dependencies
            this.commandLineParser = A.Fake<ICommandLineParser>();

            // Create test subject
            this.notificationConfigurationService = new NotificationConfigurationService(this.commandLineParser);
        }