Пример #1
0
        public bool IsValid()
        {
            var isValid = false;

            ArgumentError = false;

            var isValidDirectory = Directory.Exists(TemplateRoot);

            patchApplicationService = new PatchApplicationService(TemplateRoot);
            SourceProjectName       = patchApplicationService.GetSourceProjectName(TemplateId, TemplateRoot);
            var hasProjectFile = !string.IsNullOrEmpty(SourceProjectName);

            var totalTemplates  = TemplateData.AllTemplates.Count;
            var isValidTemplate = TemplateId > 0 && TemplateId <= totalTemplates;

            isValid = isValidDirectory && isValidTemplate && hasProjectFile && !ArgumentError;

            if (!isValidDirectory)
            {
                ErrorMessage = "The directory of your project is required.";
            }

            if (!hasProjectFile)
            {
                ErrorMessage = $"A project could not be located at: {TemplateRoot}";
            }

            if (!isValidTemplate)
            {
                ErrorMessage = "A template id is required.";
            }

            return(isValid);
        }
Пример #2
0
        private AddTemplateCommandModel ProcessArgs(string[] args)
        {
            args  = args.ToList().Except(new string[] { "add" }).ToArray();
            model = new AddTemplateCommandModel();
            var m = model;

            var tn = "";

//#if DEBUG
//            var hereDebugDirectory = @"H:\Dev\T\1\ProjectName1";//static local machine directory for debug purposes only
//            var p = new OptionSet() {
//                { "n|name=", "The name of the project", v => {m.ProjectName = v; tn = v; } },
//                { "h|here", "Use the current directory of the console", v => m.RootDirectory = hereDebugDirectory },
//                { "p|projectfolder=", "The root directory of the source project", v => m.RootDirectory = v },
//                { "t|templateid=", "The TemplateId to apply to the source project", (int v) => m.TemplateId = v },
//                { "i|install", "Install the Aurelia CLI project dependencies after template processing", (v) => m.InstallAfter = true },
//                { "b|build", "Build the Aurelia CLI project after template processing", (v) => m.BuildAfter = true },
//                { "r|run", "Run the Aurelia CLI project after template processing", (v) => m.RunAfter = true },
//                { "w|watch", "Watch the Aurelia CLI project after template processing", (v) => m.RunAfter = true }
//            };
//#else
            var p = new OptionSet()
            {
                { "n|name=", "The name of the project", v => { m.ProjectName = v; tn = v; } },
                { "h|here", "Use the current directory of the console", v => m.TemplateRoot = Environment.CurrentDirectory },
                { "p|projectfolder=", "The root directory of the source project", v => m.TemplateRoot = v },
                { "t|templateid=", "The TemplateId to apply to the source project", (int v) => m.TemplateId = v },
                { "i|install", "Install the Aurelia CLI project dependencies after template processing", (v) => m.InstallAfter = true },
                { "b|build", "Build the Aurelia CLI project after template processing", (v) => m.BuildAfter = true },
                { "r|run", "Run the Aurelia CLI project after template processing", (v) => m.RunAfter = true },
                { "w|watch", "Watch the Aurelia CLI project after template processing", (v) => m.RunAfter = true }
            };

//#endif

            ParseArgs(args, p);

            // get the project filename as generated by the users IDE
            // TODO: map the project name given by the user to their project to the relevant files during the patching application process
            model.SourceProjectName = patchApplicationService.GetSourceProjectName(model.TemplateId, model.TemplateRoot);

            m.ShowHelp = args.Count() == 0 || string.IsNullOrEmpty(args[0]);

            return(m);
        }