Esempio n. 1
0
        /// <inheritdoc />
        internal CodeGenerationConsoleManager(TextWriter writer, TextWriter errorWriter = null)
            : base(ConsoleManagerName, writer, DefaultHelpPrototype, DefaultHelpDescription, errorWriter)
        {
            DebugMessagesSwitch = Options.AddSwitch("d|debug", "Debug messages should be written.");

            // We do not need any Clean Switches after all. Instead, we factor Cleaning in terms of an MSBuild Target.
            VersionSwitch = Options.AddSwitch("v|version", "Shows the application version.");

            GoogleOrToolsVersionSwitch = Options.AddSwitch("or-tools-version", "Shows the Google.OrTools version.");

            OutputDirectoryVar = Options.AddVariable <string>("output-directory|out-dir|od"
                                                              , "The Output Directory where generate code will land.");

            GeneratedCodeRegistryFileVar = Options.AddVariable <string>("generated-code-registry-file|registry-file|rf"
                                                                        , "The Generated Code Registry File.");

            // TODO: TBD: may fill in some blanks with expected and required switches, responses, etc.
            Levels = new ErrorLevelCollection
            {
                // TODO: TBD: somehow isolate how much more of an error there might have been, i.e. internally reported exception is sufficient?
                {
                    MustSpecifyOutputDirectory,
                    () => !VersionSwitch &&
                    IsNullOrEmpty(OutputDirectoryVar),
                    () => "Must specify an Output Directory."
                },
                {
                    MustSpecifyRegistryFileName,
                    () => !VersionSwitch &&
                    !IsNullOrEmpty(OutputDirectoryVar) &&
                    IsNullOrEmpty(GeneratedCodeRegistryFileVar),
                    () => "Must specify a Registry File Name."
                },
                {
                    ErrorGeneratingCode,
                    () => !VersionSwitch &&
                    !(IsNullOrEmpty(OutputDirectoryVar) ||
                      IsNullOrEmpty(GeneratedCodeRegistryFileVar)) &&
                    GenerateCode() == ErrorGeneratingCode,
                    () => "There was an error Generating the Code."
                },
                DefaultErrorLevel
            };
        }
        internal ToolConsoleManager(TextWriter writer, TextWriter errorWriter = null)
            : base($"{typeof(ToolConsoleManager).Namespace}.Tool", writer
                   , errorWriter: errorWriter)
        {
            PrivateFactories = new ManagerFactories(this);

            VersionSwitch = Options.AddSwitch("version", OnVersion, "Shows the version of the tool.");

            // TODO: TBD: do we need to do a $"nameof(Operation)" ? or would $"{Operation}" be sufficient?
            Operation = Options.AddVariable <OperationKind?>("operation".MaySpecify()
                                                             , $"[ {nameof(Clean)} | {nameof(Generate)} ]"
                                                             + $", specify the operation the tool should perform. Default Operation is {nameof(Generate)}.");

            /* While, technically, we `MustSpecify´ Project, Output, and so on, only when the
             * Tool Operation is Generate. However, as an OptionSet, we only `MaySpecify´ the
             * options. We will further vet the Error Levels independently further in. */

            ProjectDirectory = Options.AddVariable <string>("p|project".MaySpecify(), "Project directory absolute path.");
            OutputDirectory  = Options.AddVariable <string>("o|output".MaySpecify(), "Generated source files output directory.");
            IntermediateAssembliesRegistryFileName = Options.AddVariable <string>("a|assemblies".MaySpecify(), "JSON formatted intermediate assemblies registry file name.");
            IntermediateGeneratedRegistryFileName  = Options.AddVariable <string>("g|generated".MaySpecify(), "JSON formatted intermediate generated registry file name.");

            SourcePathList          = Options.AddVariableList <string>("src|source".MaySpecify(), "Source paths included during compilation.");
            ReferencePathList       = Options.AddVariableList <string>("r|reference".MaySpecify(), "Paths to assemblies being referenced.");
            PreprocessorSymbolsList = Options.AddVariableList <string>("d|define".MaySpecify(), "Paths to preprocessor symbols.");
            GeneratorSearchPathList = Options.AddVariableList <string>("s|search".MaySpecify(), "Paths to folders that may contain generator assemblies.");

            // Which we should be able to unit test this as well, given our approach.
            ResponseFile = Options.AddVariable <string>("response".MaySpecify(), "Processes argument input from a new line delimited response file.");

            Levels = new ErrorLevelCollection
            {
                // TODO: TBD: and to be fair, we may consider an NConsole version that allows for null message factory...
                // No message should ever be relayed, this should allow --version to short-circuit the rest.
                { DefaultErrorLevel, () => VersionSwitch, () => Empty },
                // TODO: TBD: might do the same for a Help `--help´ or `--?´ option as for Version `--version´...
                { 1, () => PrivateOperation == Generate && !SourcePathList.Values.Any(), () => NoSourceFilesSpecified },
                { 2, () => IsNullOrEmpty(OutputDirectory.Value), () => OutputDirectoryMustBeSpecified },
                { 3, () => ServiceException != null, RenderServiceException },
                DefaultErrorLevel
            };
        }