예제 #1
0
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters

        /// <summary>
        /// Constructor that requires an explicit implementation of
        /// <see cref="ILoopClient"/>.
        /// </summary>
        /// <param name="commandType">Type that defines syntax for commands.</param>
        /// <param name="loopClient">The client to use.</param>
        /// <param name="argSetAttribute">Optionally provides attribute info
        /// for the argument set that will be dynamically created for this loop.</param>
        /// <param name="options">Optionally provides additional options for
        /// this loop's execution.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="commandType" />
        /// is null.</exception>
        public Loop(Type commandType, ILoopClient loopClient, ArgumentSetAttribute argSetAttribute = null, LoopOptions options = null)
        {
            if (commandType == null)
            {
                throw new ArgumentNullException(nameof(commandType));
            }

            _client = loopClient ?? throw new ArgumentNullException(nameof(loopClient));
            _client.TokenCompleter = new TokenCompleter(this);

            _options = options?.DeepClone() ?? new LoopOptions();
            _options.ParserOptions.DisplayUsageInfoOnError = false;
            _options.ParserOptions.Reporter = error => _client.OnError(error.ToString().TrimEnd());

            var inputConfigurer = _options.ParserOptions.ServiceConfigurer;

            _options.ParserOptions.ServiceConfigurer = collection => ConfigureServices(collection, inputConfigurer);

            var constructedType = ConstructCommandTypeFactory(commandType, out _objectFactory);

            _argSet = AttributeBasedArgumentDefinitionFactory.CreateArgumentSet(
                constructedType,
                attribute: argSetAttribute,
                serviceConfigurer: _options.ParserOptions.ServiceConfigurer);
        }
예제 #2
0
파일: Loop.cs 프로젝트: gitter-badger/NClap
        /// <summary>
        /// Constructor that creates a loop with a default client.
        /// </summary>
        /// <param name="parameters">Optionally provides parameters controlling
        /// the loop's input and output behaviors; if not provided, default
        /// parameters are used.</param>
        /// <param name="options">Options for loop.</param>
        public Loop(LoopInputOutputParameters parameters, LoopOptions options = null) : this(options)
        {
            var consoleInput  = parameters?.ConsoleInput ?? BasicConsoleInputAndOutput.Default;
            var consoleOutput = parameters?.ConsoleOutput ?? BasicConsoleInputAndOutput.Default;
            var keyBindingSet = parameters?.KeyBindingSet ?? ConsoleKeyBindingSet.Default;

            var lineInput = parameters?.LineInput ?? new ConsoleLineInput(
                consoleOutput,
                new ConsoleInputBuffer(),
                new ConsoleHistory(),
                GenerateCompletions);

            lineInput.Prompt = parameters?.Prompt ?? Strings.DefaultPrompt;

            ConsoleReader = new ConsoleReader(lineInput, consoleInput, consoleOutput, keyBindingSet);

            var consoleClient = new ConsoleLoopClient(
                ConsoleReader,
                parameters?.ErrorWriter ?? Console.Error);

            consoleClient.Reader.CommentCharacter = options?.EndOfLineCommentCharacter;

            Client = consoleClient;
        }
예제 #3
0
 /// <summary>
 /// Constructor that creates a loop with a default client.
 /// </summary>
 /// <param name="commandType">Type that defines syntax for commands.</param>
 /// <param name="parameters">Optionally provides parameters controlling
 /// the loop's input and output behaviors; if not provided, default
 /// parameters are used.</param>
 /// <param name="argSetAttribute">Optionally provides attribute info
 /// for the argument set that will be dynamically created for this loop.</param>
 /// <param name="options">Optionally provides additional options for
 /// this loop's execution.</param>
 public Loop(Type commandType, LoopInputOutputParameters parameters = null, ArgumentSetAttribute argSetAttribute = null, LoopOptions options = null)
     : this(commandType, CreateClient(parameters ?? new LoopInputOutputParameters()), argSetAttribute, options)
 {
 }
예제 #4
0
파일: Loop.cs 프로젝트: gitter-badger/NClap
 /// <summary>
 /// Shared private constructor used internally by all public
 /// constructors.
 /// </summary>
 /// <param name="options">Options for loop.</param>
 private Loop(LoopOptions options)
 {
     EndOfLineCommentCharacter = options?.EndOfLineCommentCharacter;
 }
예제 #5
0
파일: Loop.cs 프로젝트: gitter-badger/NClap
 /// <summary>
 /// Constructor that requires an explicit implementation of
 /// <see cref="ILoopClient"/>.
 /// </summary>
 /// <param name="loopClient">The client to use.</param>
 /// <param name="options">Options for loop.</param>
 public Loop(ILoopClient loopClient, LoopOptions options = null) : this(options)
 {
     Client = loopClient ?? throw new ArgumentNullException(nameof(loopClient));
 }