/// <summary> /// Performs the validation. /// </summary> /// <param name="option">The <see cref="CommandOption"/>.</param> /// <param name="context">The <see cref="ValidationContext"/>.</param> /// <returns>The <see cref="ValidationResult"/>.</returns> public ValidationResult GetValidationResult(CommandOption option, ValidationContext context) { if (option.Value() != null && !File.Exists(option.Value()) && ResourceManager.GetScriptContent(option.Value()) == null) { return(new ValidationResult($"The file or embedded resource '{option.Value()}' does not exist.")); } return(ValidationResult.Success); }
/// <summary> /// Initializes a new instance of the <see cref="CodeGenConsole"/> class. /// </summary> private CodeGenConsole() { App = new CommandLineApplication(false) { Name = "beef.codegen", Description = "Business Entity Execution Framework (Beef) Code Generator." }; App.HelpOption(true); _configArg = App.Argument("config", "CodeGeneration configuration XML file.") .IsRequired() .Accepts(v => v.ExistingFile()); _scriptOpt = App.Option("-s|--script", "Execution script file or embedded resource name.", CommandOptionType.SingleValue) .IsRequired() .Accepts(v => v.Use(new FileResourceValidator())); _templateOpt = App.Option("-t|--template", "Templates path (defaults to embedded resources).", CommandOptionType.SingleValue) .Accepts(v => v.ExistingDirectory()); _outputOpt = App.Option("-o|--output", "Output path (defaults to current path).", CommandOptionType.SingleValue) .Accepts(v => v.ExistingDirectory()); _assembliesOpt = App.Option("-a|--assembly", "Assembly name containing scripts (multiple can be specified).", CommandOptionType.MultipleValue) .Accepts(v => v.Use(new AssemblyValidator(_assemblies))); _paramsOpt = App.Option("-p|--param", "Name=Value pair(s) passed into code generation.", CommandOptionType.MultipleValue) .Accepts(v => v.Use(new ParamsValidator())); App.OnExecute(() => { // Check the Execution script file or embedded resource names. if (!File.Exists(_scriptOpt.Value()) && ResourceManager.GetScriptContent(_scriptOpt.Value()) == null) { throw new InvalidOperationException($"The file or embedded resource '{_scriptOpt.Value()}' does not exist."); } return(RunRunAwayAsync()); }); }