Ejemplo n.º 1
0
        ListAvailableCommands()
        {
            foreach (PyRevitClone clone in PyRevitClones.GetRegisteredClones())
            {
                PyRevitCLIAppCmds.PrintHeader($"Commands in Clone \"{clone.Name}\"");
                foreach (PyRevitExtension ext in clone.GetExtensions())
                {
                    if (ext.Type == PyRevitExtensionTypes.UIExtension)
                    {
                        foreach (PyRevitRunnerCommand cmd in ext.GetCommands())
                        {
                            Console.WriteLine(cmd);
                        }
                    }
                }
            }

            foreach (PyRevitExtension ext in PyRevitExtensions.GetInstalledExtensions())
            {
                if (ext.Type == PyRevitExtensionTypes.UIExtension)
                {
                    PyRevitCLIAppCmds.PrintHeader($"Commands in Extension \"{ext.Name}\"");
                    foreach (PyRevitRunnerCommand cmd in ext.GetCommands())
                    {
                        Console.WriteLine(cmd);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 GetSetCloneOrigin(string cloneName, string originUrl, bool reset)
 {
     if (cloneName != null)
     {
         var clone = PyRevitClones.GetRegisteredClone(cloneName);
         if (clone.IsRepoDeploy)
         {
             if (originUrl != null || reset)
             {
                 string newUrl =
                     reset ? PyRevitLabsConsts.OriginalRepoGitPath : originUrl;
                 clone.SetOrigin(newUrl);
             }
             else
             {
                 Console.WriteLine(string.Format("Clone \"{0}\" origin is at \"{1}\"",
                                                 clone.Name, clone.Origin));
             }
         }
         else
         {
             PyRevitCLIAppCmds.ReportCloneAsNoGit(clone);
         }
     }
 }
Ejemplo n.º 3
0
 GetSetCloneBranch(string cloneName, string branchName)
 {
     if (cloneName != null)
     {
         var clone = PyRevitClones.GetRegisteredClone(cloneName);
         if (clone != null)
         {
             if (clone.IsRepoDeploy)
             {
                 if (branchName != null)
                 {
                     clone.SetBranch(branchName);
                 }
                 else
                 {
                     Console.WriteLine(string.Format("Clone \"{0}\" is on branch \"{1}\"",
                                                     clone.Name, clone.Branch));
                 }
             }
             else
             {
                 PyRevitCLIAppCmds.ReportCloneAsNoGit(clone);
             }
         }
     }
 }
Ejemplo n.º 4
0
 private static void PrintBuildInfo()
 {
     PyRevitCLIAppCmds.PrintHeader("Supported Revits");
     foreach (var revit in RevitProduct.ListSupportedProducts().OrderByDescending(x => x.Version))
     {
         Console.WriteLine(string.Format("{0} | Version: {1} | Build: {2}({3})", revit.Name, revit.Version, revit.BuildNumber, revit.BuildTarget));
     }
 }
Ejemplo n.º 5
0
 PrintExtensionDefinitions(string searchPattern, string headerPrefix = "Registered")
 {
     PyRevitCLIAppCmds.PrintHeader(string.Format("{0} Extensions", headerPrefix));
     foreach (PyRevitExtensionDefinition ext in PyRevitExtensions.LookupRegisteredExtensions(searchPattern))
     {
         Console.WriteLine(ext);
     }
 }
Ejemplo n.º 6
0
        UpdateClone(bool allClones, string cloneName, GitInstallerCredentials credentials)
        {
            // TODO: ask for closing running Revits

            // prepare a list of clones to be updated
            var targetClones = new List <PyRevitClone>();
            // separate the clone that this process might be running from
            // this is used to update this clone from outside since the dlls will be locked
            PyRevitClone myClone = null;

            // all clones
            if (allClones)
            {
                foreach (var clone in PyRevitClones.GetRegisteredClones())
                {
                    if (PyRevitCLIAppCmds.IsRunningInsideClone(clone))
                    {
                        myClone = clone;
                    }
                    else
                    {
                        targetClones.Add(clone);
                    }
                }
            }
            // or single clone
            else
            {
                if (cloneName != null)
                {
                    var clone = PyRevitClones.GetRegisteredClone(cloneName);
                    if (PyRevitCLIAppCmds.IsRunningInsideClone(clone))
                    {
                        myClone = clone;
                    }
                    else
                    {
                        targetClones.Add(clone);
                    }
                }
            }

            // update clones that do not include this process
            foreach (var clone in targetClones)
            {
                logger.Debug("Updating clone \"{0}\"", clone.Name);
                PyRevitClones.Update(clone, credentials);
            }

            // now update myClone if any, as last step
            if (myClone != null)
            {
                throw new PyRevitException("Can not update clone that contains this command line utility. "
                                           + "Use installer to update.");
            }
        }
Ejemplo n.º 7
0
 PrintExtensionSearchPaths()
 {
     PyRevitCLIAppCmds.PrintHeader("Default Extension Search Path");
     Console.WriteLine(PyRevitConsts.DefaultExtensionsPath);
     PyRevitCLIAppCmds.PrintHeader("Extension Search Paths");
     foreach (var searchPath in PyRevitExtensions.GetRegisteredExtensionSearchPaths())
     {
         Console.WriteLine(searchPath);
     }
 }
Ejemplo n.º 8
0
 PrintExtensionLookupSources()
 {
     PyRevitCLIAppCmds.PrintHeader("Extension Sources - Default");
     Console.WriteLine(PyRevitExtensions.GetDefaultExtensionLookupSource());
     PyRevitCLIAppCmds.PrintHeader("Extension Sources - Additional");
     foreach (var extLookupSrc in PyRevitExtensions.GetRegisteredExtensionLookupSources())
     {
         Console.WriteLine(extLookupSrc);
     }
 }
Ejemplo n.º 9
0
 PrintCloneEngines(string cloneName)
 {
     if (cloneName != null)
     {
         var clone = PyRevitClones.GetRegisteredClone(cloneName);
         PyRevitCLIAppCmds.PrintHeader(string.Format("Deployments for \"{0}\"", clone.Name));
         foreach (var engine in clone.GetConfiguredEngines())
         {
             Console.WriteLine(engine);
         }
     }
 }
Ejemplo n.º 10
0
        PrintExtensions(IEnumerable <PyRevitExtension> extList = null, string headerPrefix = "Installed")
        {
            if (extList is null)
            {
                extList = PyRevitExtensions.GetInstalledExtensions();
            }

            PyRevitCLIAppCmds.PrintHeader(string.Format("{0} Extensions", headerPrefix));
            foreach (PyRevitExtension ext in extList.OrderBy(x => x.Name))
            {
                Console.WriteLine(ext);
            }
        }
Ejemplo n.º 11
0
 PrintAttachments(int revitYear = 0)
 {
     PyRevitCLIAppCmds.PrintHeader("Attachments");
     foreach (var attachment in PyRevitAttachments.GetAttachments().OrderByDescending(x => x.Product.Version))
     {
         if (revitYear == 0)
         {
             Console.WriteLine(attachment);
         }
         else if (revitYear == attachment.Product.ProductYear)
         {
             Console.WriteLine(attachment);
         }
     }
 }
Ejemplo n.º 12
0
        PrintClones()
        {
            PyRevitCLIAppCmds.PrintHeader("Registered Clones (full git repos)");
            var clones = PyRevitClones.GetRegisteredClones().OrderBy(x => x.Name);

            foreach (var clone in clones.Where(c => c.IsRepoDeploy))
            {
                Console.WriteLine(clone);
            }

            PyRevitCLIAppCmds.PrintHeader("Registered Clones (deployed from archive/image)");
            foreach (var clone in clones.Where(c => !c.IsRepoDeploy))
            {
                Console.WriteLine(clone);
            }
        }
Ejemplo n.º 13
0
 PrintCloneDeployments(string cloneName)
 {
     if (cloneName != null)
     {
         var clone = PyRevitClones.GetRegisteredClone(cloneName);
         PyRevitCLIAppCmds.PrintHeader(string.Format("Deployments for \"{0}\"", clone.Name));
         foreach (var dep in clone.GetConfiguredDeployments())
         {
             Console.WriteLine(string.Format("\"{0}\" deploys:", dep.Name));
             foreach (var path in dep.Paths)
             {
                 Console.WriteLine("    " + path);
             }
             Console.WriteLine();
         }
     }
 }
Ejemplo n.º 14
0
 PrintLocalRevits(bool running = false)
 {
     if (running)
     {
         PyRevitCLIAppCmds.PrintHeader("Running Revit Instances");
         foreach (var revit in RevitController.ListRunningRevits().OrderByDescending(x => x.RevitProduct.Version))
         {
             Console.WriteLine(revit);
         }
     }
     else
     {
         PyRevitCLIAppCmds.PrintHeader("Installed Revits");
         foreach (var revit in RevitProduct.ListInstalledProducts().OrderByDescending(x => x.Version))
         {
             Console.WriteLine(revit);
         }
     }
 }
        PrintReleases(string searchPattern, bool latest = false, bool printReleaseNotes = false, bool listPreReleases = false)
        {
            PyRevitCLIAppCmds.PrintHeader("Releases");
            List <PyRevitRelease> releasesToList = new List <PyRevitRelease>();

            // determine latest release
            if (latest)
            {
                var latestRelease = PyRevitReleases.GetLatestRelease(includePreRelease: listPreReleases);

                if (latestRelease is null)
                {
                    throw new PyRevitException("Can not determine latest release.");
                }

                releasesToList.Add(latestRelease);
            }
            else
            {
                if (searchPattern != null)
                {
                    releasesToList = PyRevitReleases.FindReleases(searchPattern, includePreRelease: listPreReleases);
                }
                else
                {
                    releasesToList = PyRevitReleases.GetReleases().Where(r => r.IsPyRevitRelease).ToList();
                }
            }

            foreach (var prelease in releasesToList)
            {
                Console.WriteLine(prelease);
                if (printReleaseNotes)
                {
                    Console.WriteLine(prelease.ReleaseNotes.Indent(1));
                }
            }
        }
Ejemplo n.º 16
0
 GetSetCloneCommit(string cloneName, string commitHash)
 {
     if (cloneName != null)
     {
         var clone = PyRevitClones.GetRegisteredClone(cloneName);
         if (clone.IsRepoDeploy)
         {
             if (commitHash != null)
             {
                 clone.SetCommit(commitHash);
             }
             else
             {
                 Console.WriteLine(string.Format("Clone \"{0}\" is on commit \"{1}\"",
                                                 clone.Name, clone.Commit));
             }
         }
         else
         {
             PyRevitCLIAppCmds.ReportCloneAsNoGit(clone);
         }
     }
 }
Ejemplo n.º 17
0
        RunExtensionCommand(string commandName, string targetFile, string revitYear, PyRevitRunnerOptions runOptions, bool targetIsFileList = false)
        {
            // verify command
            if (commandName is null || commandName == string.Empty)
            {
                throw new Exception("Command name must be provided.");
            }

            // try target revit year
            int revitYearNumber = 0;

            int.TryParse(revitYear, out revitYearNumber);


            // setup a list of models
            var modelFiles = new List <string>();

            // if target file is a list of model paths
            if (targetIsFileList)
            {
                // attempt at reading the list file and grab the model files only
                foreach (var modelPath in File.ReadAllLines(targetFile))
                {
                    modelFiles.Add(modelPath);
                }
            }
            // otherwise just work on this model
            else
            {
                modelFiles.Add(targetFile);
            }


            // verify all models are accessible
            foreach (string modelFile in modelFiles)
            {
                if (!CommonUtils.VerifyFile(modelFile))
                {
                    throw new Exception($"Model does not exist at \"{modelFile}\"");
                }
            }


            // determine which Revit version to launch
            if (revitYearNumber != 0)
            {
                foreach (string modelFile in modelFiles)
                {
                    var modelInfo = new RevitModelFile(modelFile);

                    // if specific revit version is provided, make sure model is not newer
                    if (modelInfo.RevitProduct != null)
                    {
                        if (modelInfo.RevitProduct.ProductYear > revitYearNumber)
                        {
                            throw new Exception($"Model at \"{modelFile}\" is newer than the specified version: {revitYearNumber}");
                        }
                    }
                    else
                    {
                        throw new Exception($"Can not detect the Revit version of model at \"{modelFile}\". Model might be newer than specified version {revitYearNumber}.");
                    }
                }
            }
            else
            {
                // determine revit model version from given files
                foreach (string modelFile in modelFiles)
                {
                    var modelInfo = new RevitModelFile(modelFile);
                    if (modelInfo.RevitProduct != null)
                    {
                        if (revitYearNumber == 0)
                        {
                            revitYearNumber = modelInfo.RevitProduct.ProductYear;
                        }
                        else if (modelInfo.RevitProduct.ProductYear > revitYearNumber)
                        {
                            revitYearNumber = modelInfo.RevitProduct.ProductYear;
                        }
                    }
                }

                // if could not determine revit version from given files,
                // use latest version
                if (revitYearNumber == 0)
                {
                    revitYearNumber = RevitProduct.ListInstalledProducts().Max(r => r.ProductYear);
                }
            }

            // now run
            if (revitYearNumber != 0)
            {
                // determine attached clone
                var attachment = PyRevitAttachments.GetAttached(revitYearNumber);
                if (attachment is null)
                {
                    logger.Error($"pyRevit is not attached to Revit \"{revitYearNumber}\". " +
                                 "Runner needs to use the attached clone and engine to execute the script.");
                }
                else
                {
                    // determine script to run
                    string commandScriptPath = null;

                    if (!CommonUtils.VerifyPythonScript(commandName))
                    {
                        logger.Debug("Input is not a script file \"{0}\"", commandName);
                        logger.Debug("Attempting to find run command matching \"{0}\"", commandName);

                        // try to find run command in attached clone being used for execution
                        // if not found, try to get run command from all other installed extensions
                        var targetExtensions = new List <PyRevitExtension>();
                        if (attachment.Clone != null)
                        {
                            targetExtensions.AddRange(attachment.Clone.GetExtensions());
                        }
                        targetExtensions.AddRange(PyRevitExtensions.GetInstalledExtensions());

                        foreach (PyRevitExtension ext in targetExtensions)
                        {
                            logger.Debug("Searching for run command in: \"{0}\"", ext.ToString());
                            if (ext.Type == PyRevitExtensionTypes.UIExtension)
                            {
                                try {
                                    var cmdScript = ext.GetCommand(commandName);
                                    if (cmdScript != null)
                                    {
                                        logger.Debug("Run command matching \"{0}\" found: \"{1}\"",
                                                     commandName, cmdScript);
                                        commandScriptPath = cmdScript.Path;
                                        break;
                                    }
                                }
                                catch {
                                    // does not include command
                                    continue;
                                }
                            }
                        }
                    }
                    else
                    {
                        commandScriptPath = commandName;
                    }

                    // if command is not found, stop
                    if (commandScriptPath is null)
                    {
                        throw new PyRevitException(
                                  string.Format("Run command not found: \"{0}\"", commandName)
                                  );
                    }

                    // RUN!
                    var execEnv = PyRevitRunner.Run(
                        attachment,
                        commandScriptPath,
                        modelFiles,
                        runOptions
                        );

                    // print results (exec env)
                    PyRevitCLIAppCmds.PrintHeader("Execution Environment");
                    Console.WriteLine(string.Format("Execution Id: \"{0}\"", execEnv.ExecutionId));
                    Console.WriteLine(string.Format("Product: {0}", execEnv.Revit));
                    Console.WriteLine(string.Format("Clone: {0}", execEnv.Clone));
                    Console.WriteLine(string.Format("Engine: {0}", execEnv.Engine));
                    Console.WriteLine(string.Format("Script: \"{0}\"", execEnv.Script));
                    Console.WriteLine(string.Format("Working Directory: \"{0}\"", execEnv.WorkingDirectory));
                    Console.WriteLine(string.Format("Journal File: \"{0}\"", execEnv.JournalFile));
                    Console.WriteLine(string.Format("Manifest File: \"{0}\"", execEnv.PyRevitRunnerManifestFile));
                    Console.WriteLine(string.Format("Log File: \"{0}\"", execEnv.LogFile));
                    // report whether the env was purge or not
                    if (execEnv.Purged)
                    {
                        Console.WriteLine("Execution env is successfully purged.");
                    }

                    // print target models
                    if (execEnv.ModelPaths.Count() > 0)
                    {
                        PyRevitCLIAppCmds.PrintHeader("Target Models");
                        foreach (var modelPath in execEnv.ModelPaths)
                        {
                            Console.WriteLine(modelPath);
                        }
                    }

                    // print log file contents if exists
                    if (File.Exists(execEnv.LogFile))
                    {
                        PyRevitCLIAppCmds.PrintHeader("Execution Log");
                        Console.WriteLine(File.ReadAllText(execEnv.LogFile));
                    }
                }
            }
        }
Ejemplo n.º 18
0
        // cli argument processor
        private static void ProcessArguments()
        {
            if (IsHelpUsagePatternMode)
            {
                Console.WriteLine(UsagePatterns.Replace("\t", "    "));
            }

            else if (IsVersionMode)
            {
                PyRevitCLIAppCmds.PrintVersion(checkUpdates: true);
            }

            else if (all("wiki"))
            {
                CommonUtils.OpenUrl(PyRevitLabsConsts.WikiUrl);
            }

            else if (all("blog"))
            {
                CommonUtils.OpenUrl(PyRevitLabsConsts.BlogsUrl);
            }

            else if (all("docs"))
            {
                CommonUtils.OpenUrl(PyRevitLabsConsts.DocsUrl);
            }

            else if (all("source"))
            {
                CommonUtils.OpenUrl(PyRevitLabsConsts.SourceRepoUrl);
            }

            else if (all("youtube"))
            {
                CommonUtils.OpenUrl(PyRevitLabsConsts.YoutubeUrl);
            }

            else if (all("support"))
            {
                CommonUtils.OpenUrl(PyRevitLabsConsts.SupportUrl);
            }

            else if (all("env"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Env);
                }
                else
                {
                    PyRevitCLIAppCmds.MakeEnvReport(json: arguments["--json"].IsTrue);
                }
            }

            else if (all("update") && !any("clones", "extensions"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Update);
                }
                else
                {
                    PyRevitCLIAppCmds.UpdateRemoteDataSources();
                }
            }

            else if (all("clone"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Clone);
                }
                else
                {
                    PyRevitCLICloneCmds.CreateClone(
                        cloneName: TryGetValue("<clone_name>"),
                        deployName: TryGetValue("<deployment_name>"),
                        branchName: TryGetValue("--branch"),
                        repoUrl: TryGetValue("--source"),
                        imagePath: TryGetValue("--image"),
                        destPath: TryGetValue("--dest"),
                        credentials: TryGetCredentials()
                        );
                }
            }

            else if (all("clones"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Clones);
                }

                else if (all("info"))
                {
                    PyRevitCLICloneCmds.PrintCloneInfo(TryGetValue("<clone_name>"));
                }

                else if (all("open"))
                {
                    PyRevitCLICloneCmds.OpenClone(TryGetValue("<clone_name>"));
                }

                else if (all("add"))
                {
                    if (all("this"))
                    {
                        PyRevitCLICloneCmds.RegisterClone(
                            TryGetValue("<clone_name>"),
                            Path.GetDirectoryName(CLIPath),
                            force: arguments["--force"].IsTrue
                            );
                    }
                    else
                    {
                        PyRevitCLICloneCmds.RegisterClone(
                            TryGetValue("<clone_name>"),
                            TryGetValue("<clone_path>"),
                            force: arguments["--force"].IsTrue
                            );
                    }
                }

                else if (all("forget"))
                {
                    PyRevitCLICloneCmds.ForgetClone(
                        allClones: arguments["--all"].IsTrue,
                        cloneName: TryGetValue("<clone_name>")
                        );
                }

                else if (all("rename"))
                {
                    PyRevitCLICloneCmds.RenameClone(
                        cloneName: TryGetValue("<clone_name>"),
                        cloneNewName: TryGetValue("<clone_new_name>")
                        );
                }

                else if (all("delete"))
                {
                    PyRevitCLICloneCmds.DeleteClone(
                        allClones: arguments["--all"].IsTrue,
                        cloneName: TryGetValue("<clone_name>"),
                        clearConfigs: arguments["--clearconfigs"].IsTrue
                        );
                }

                else if (all("branch"))
                {
                    PyRevitCLICloneCmds.GetSetCloneBranch(
                        cloneName: TryGetValue("<clone_name>"),
                        branchName: TryGetValue("<branch_name>")
                        );
                }

                else if (all("version"))
                {
                    PyRevitCLICloneCmds.GetSetCloneTag(
                        cloneName: TryGetValue("<clone_name>"),
                        tagName: TryGetValue("<tag_name>")
                        );
                }

                else if (all("commit"))
                {
                    PyRevitCLICloneCmds.GetSetCloneCommit(
                        cloneName: TryGetValue("<clone_name>"),
                        commitHash: TryGetValue("<commit_hash>")
                        );
                }

                else if (all("origin"))
                {
                    PyRevitCLICloneCmds.GetSetCloneOrigin(
                        cloneName: TryGetValue("<clone_name>"),
                        originUrl: TryGetValue("<origin_url>"),
                        reset: arguments["--reset"].IsTrue
                        );
                }

                else if (all("deployments"))
                {
                    PyRevitCLICloneCmds.PrintCloneDeployments(TryGetValue("<clone_name>"));
                }

                else if (all("engines"))
                {
                    PyRevitCLICloneCmds.PrintCloneEngines(TryGetValue("<clone_name>"));
                }

                else if (all("update"))
                {
                    PyRevitCLICloneCmds.UpdateClone(
                        allClones: arguments["--all"].IsTrue,
                        cloneName: TryGetValue("<clone_name>"),
                        credentials: TryGetCredentials()
                        );
                }

                else
                {
                    PyRevitCLICloneCmds.PrintClones();
                }
            }

            else if (all("attach"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Attach);
                }
                else
                {
                    // get clone
                    var clone = PyRevitClones.GetRegisteredClone(TryGetValue("<clone_name>"));

                    // determine version
                    var engStrVer = TryGetValue("<engine_version>");
                    PyRevitEngineVersion engineVersion = null;
                    if (arguments["default"].IsTrue)
                    {
                        engineVersion = PyRevitEngineVersion.Default;
                    }
                    else
                    {
                        // try parse the engine version as an integer e.g. 277 for 2.7.7
                        if (int.TryParse(engStrVer, out var engIntVer))
                        {
                            engineVersion = (PyRevitEngineVersion)engIntVer;
                        }
                    }

                    if (engineVersion is null)
                    {
                        // then engine must be an engine id
                        PyRevitCLICloneCmds.AttachClone(
                            clone: clone,
                            engineId: engStrVer,
                            revitYear: TryGetValue("<revit_year>"),
                            installed: arguments["--installed"].IsTrue,
                            attached: arguments["--attached"].IsTrue,
                            allUsers: arguments["--allusers"].IsTrue
                            );
                    }
                    else
                    {
                        PyRevitCLICloneCmds.AttachClone(
                            clone: clone,
                            engineVersion: engineVersion,
                            revitYear: TryGetValue("<revit_year>"),
                            installed: arguments["--installed"].IsTrue,
                            attached: arguments["--attached"].IsTrue,
                            allUsers: arguments["--allusers"].IsTrue
                            );
                    }
                }
            }

            else if (all("detach"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Detach);
                }
                else
                {
                    PyRevitCLICloneCmds.DetachClone(
                        revitYear: TryGetValue("<revit_year>"),
                        all: arguments["--all"].IsTrue,
                        currentAndAllUsers: true
                        );
                }
            }

            else if (all("attached"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Attached);
                }
                else
                {
                    PyRevitCLICloneCmds.ListAttachments(revitYear: TryGetValue("<revit_year>"));
                }
            }

            else if (all("switch"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Switch);
                }
                else
                {
                    PyRevitCLICloneCmds.SwitchAttachment(
                        cloneName: TryGetValue("<clone_name>"),
                        revitYear: TryGetValue("<revit_year>")
                        );
                }
            }

            else if (all("extend"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Extend);
                }

                else if (any("ui", "lib"))
                {
                    PyRevitCLIExtensionCmds.Extend(
                        ui: arguments["ui"].IsTrue,
                        lib: arguments["lib"].IsTrue,
                        extName: TryGetValue("<extension_name>"),
                        destPath: TryGetValue("--dest"),
                        repoUrl: TryGetValue("<repo_url>"),
                        branchName: TryGetValue("--branch"),
                        credentials: TryGetCredentials()
                        );
                }

                else
                {
                    PyRevitCLIExtensionCmds.Extend(
                        extName: TryGetValue("<extension_name>"),
                        destPath: TryGetValue("--dest"),
                        branchName: TryGetValue("--branch")
                        );
                }
            }

            else if (all("extensions"))
            {
                if (all("search"))
                {
                    PyRevitCLIExtensionCmds.PrintExtensionDefinitions(
                        searchPattern: TryGetValue("<search_pattern>"),
                        headerPrefix: "Matched"
                        );
                }

                else if (any("info", "help"))
                {
                    PyRevitCLIExtensionCmds.ProcessExtensionInfoCommands(
                        extName: TryGetValue("<extension_name>"),
                        info: arguments["info"].IsTrue,
                        help: arguments["help"].IsTrue
                        );
                }

                else if (all("open"))
                {
                    PyRevitCLIExtensionCmds.ProcessExtensionOpenCommand(
                        cloneName: TryGetValue("<clone_name>"),
                        extName: TryGetValue("<extension_name>")
                        );
                }

                else if (all("delete"))
                {
                    PyRevitCLIExtensionCmds.DeleteExtension(TryGetValue("<extension_name>"));
                }

                else if (all("origin"))
                {
                    PyRevitCLIExtensionCmds.GetSetExtensionOrigin(
                        extName: TryGetValue("<extension_name>"),
                        originUrl: TryGetValue("<origin_url>"),
                        reset: arguments["--reset"].IsTrue
                        );
                }

                else if (all("paths"))
                {
                    if (IsHelpMode)
                    {
                        PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.ExtensionsPaths);
                    }

                    else if (all("add"))
                    {
                        PyRevitCLIExtensionCmds.AddExtensionPath(
                            searchPath: TryGetValue("<extensions_path>")
                            );
                    }

                    else if (all("forget"))
                    {
                        PyRevitCLIExtensionCmds.ForgetAllExtensionPaths(
                            all: arguments["--all"].IsTrue,
                            searchPath: TryGetValue("<extensions_path>")
                            );
                    }

                    else
                    {
                        PyRevitCLIExtensionCmds.PrintExtensionSearchPaths();
                    }
                }

                else if (any("enable", "disable"))
                {
                    PyRevitCLIExtensionCmds.ToggleExtension(
                        enable: arguments["enable"].IsTrue,
                        cloneName: TryGetValue("<clone_name>"),
                        extName: TryGetValue("<extension_name>")
                        );
                }

                else if (all("sources"))
                {
                    if (IsHelpMode)
                    {
                        PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.ExtensionsSources);
                    }

                    else if (all("add"))
                    {
                        PyRevitCLIExtensionCmds.AddExtensionLookupSource(
                            lookupPath: TryGetValue("<source_json_or_url>")
                            );
                    }

                    else if (all("forget"))
                    {
                        PyRevitCLIExtensionCmds.ForgetExtensionLookupSources(
                            all: arguments["--all"].IsTrue,
                            lookupPath: TryGetValue("<source_json_or_url>")
                            );
                    }

                    else
                    {
                        PyRevitCLIExtensionCmds.PrintExtensionLookupSources();
                    }
                }

                else if (all("update"))
                {
                    PyRevitCLIExtensionCmds.UpdateExtension(
                        all: arguments["--all"].IsTrue,
                        extName: TryGetValue("<extension_name>"),
                        credentials: TryGetCredentials()
                        );
                }

                else if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Extensions);
                }

                else
                {
                    PyRevitCLIExtensionCmds.PrintExtensions();
                }
            }

            else if (all("releases"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Releases);
                }

                else if (all("open"))
                {
                    PyRevitCLIReleaseCmds.OpenReleasePage(
                        searchPattern: TryGetValue("<search_pattern>"),
                        latest: arguments["latest"].IsTrue,
                        listPreReleases: arguments["--pre"].IsTrue
                        );
                }

                else if (all("download"))
                {
                    PyRevitCLIReleaseCmds.DownloadReleaseAsset(
                        arguments["archive"].IsTrue ? GithubReleaseAssetType.Archive : GithubReleaseAssetType.Installer,
                        destPath: TryGetValue("--dest"),
                        searchPattern: TryGetValue("<search_pattern>"),
                        latest: arguments["latest"].IsTrue,
                        listPreReleases: arguments["--pre"].IsTrue
                        );
                }

                else
                {
                    PyRevitCLIReleaseCmds.PrintReleases(
                        searchPattern: TryGetValue("<search_pattern>"),
                        latest: arguments["latest"].IsTrue,
                        printReleaseNotes: arguments["--notes"].IsTrue,
                        listPreReleases: arguments["--pre"].IsTrue
                        );
                }
            }

            else if (all("revits"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Revits);
                }

                else if (all("killall"))
                {
                    PyRevitCLIRevitCmds.KillAllRevits(
                        revitYear: TryGetValue("<revit_year>")
                        );
                }

                else if (all("fileinfo"))
                {
                    PyRevitCLIRevitCmds.ProcessFileInfo(
                        targetPath: TryGetValue("<file_or_dir_path>"),
                        outputCSV: TryGetValue("--csv"),
                        IncludeRVT: arguments["--rvt"].IsTrue,
                        includeRTE: arguments["--rte"].IsTrue,
                        includeRFA: arguments["--rfa"].IsTrue,
                        includeRFT: arguments["--rft"].IsTrue
                        );
                }

                else if (arguments["--supported"].IsTrue)
                {
                    PyRevitCLIRevitCmds.ProcessBuildInfo(
                        outputCSV: TryGetValue("--csv")
                        );
                }

                else
                {
                    PyRevitCLIRevitCmds.PrintLocalRevits(running: arguments["--installed"].IsFalse);
                }
            }

            else if (all("run"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Run);
                }
                else if (all("commands"))
                {
                    PyRevitCLIRevitCmds.ListAvailableCommands();
                }
                else
                {
                    var modelList = TryGetValue("--models");
                    if (modelList != null)
                    {
                        PyRevitCLIRevitCmds.RunExtensionCommand(
                            commandName: TryGetValue("<script_or_command_name>"),
                            targetFile: modelList,
                            revitYear: TryGetValue("--revit"),
                            runOptions: new PyRevitRunnerOptions()
                        {
                            PurgeTempFiles = arguments["--purge"].IsTrue,
                            ImportPath     = TryGetValue("--import", null)
                        },
                            targetIsFileList: true
                            );
                    }
                    else
                    {
                        PyRevitCLIRevitCmds.RunExtensionCommand(
                            commandName: TryGetValue("<script_or_command_name>"),
                            targetFile: TryGetValue("<model_file>"),
                            revitYear: TryGetValue("--revit"),
                            runOptions: new PyRevitRunnerOptions()
                        {
                            PurgeTempFiles = arguments["--purge"].IsTrue,
                            ImportPath     = TryGetValue("--import", null)
                        }
                            );
                    }
                }
            }

            else if (all("caches"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Caches);
                }

                else if (all("bim360", "clear"))
                {
                    PyRevitCLIAppCmds.ClearCaches(
                        allCaches: arguments["--all"].IsTrue,
                        revitYear: TryGetValue("<revit_year>"),
                        cachetype: TargetCacheType.BIM360Cache
                        );
                }

                else if (all("clear"))
                {
                    PyRevitCLIAppCmds.ClearCaches(
                        allCaches: arguments["--all"].IsTrue,
                        revitYear: TryGetValue("<revit_year>"),
                        cachetype: TargetCacheType.PyRevitCache
                        );
                }
            }

            else if (all("config"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Config);
                }
                else
                {
                    PyRevitCLIConfigCmds.SeedConfigs(
                        templateConfigFilePath: TryGetValue("--from")
                        );
                }
            }

            else if (all("configs"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Configs);
                }

                else if (all("bincache"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetBinaryCaches(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Binary cache is {0}",
                                                        PyRevitConfigs.GetBinaryCaches() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("checkupdates"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetCheckUpdates(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Check Updates is {0}",
                                                        PyRevitConfigs.GetCheckUpdates() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("autoupdate"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetAutoUpdate(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Auto Update is {0}",
                                                        PyRevitConfigs.GetAutoUpdate() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("rocketmode"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetRocketMode(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Rocket Mode is {0}",
                                                        PyRevitConfigs.GetRocketMode() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("logs"))
                {
                    if (all("none"))
                    {
                        PyRevitConfigs.SetLoggingLevel(PyRevitLogLevels.Quiet);
                    }

                    else if (all("verbose"))
                    {
                        PyRevitConfigs.SetLoggingLevel(PyRevitLogLevels.Verbose);
                    }

                    else if (all("debug"))
                    {
                        PyRevitConfigs.SetLoggingLevel(PyRevitLogLevels.Debug);
                    }

                    else
                    {
                        Console.WriteLine(string.Format("Logging Level is {0}", PyRevitConfigs.GetLoggingLevel().ToString()));
                    }
                }

                else if (all("filelogging"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetFileLogging(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("File Logging is {0}",
                                                        PyRevitConfigs.GetFileLogging() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("startuptimeout"))
                {
                    if (arguments["<timeout>"] is null)
                    {
                        Console.WriteLine(string.Format("Startup log timeout is set to: {0}",
                                                        PyRevitConfigs.GetStartupLogTimeout()));
                    }
                    else
                    {
                        PyRevitConfigs.SetStartupLogTimeout(int.Parse(TryGetValue("<timeout>")));
                    }
                }

                else if (all("loadbeta"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetLoadBetaTools(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Load Beta is {0}",
                                                        PyRevitConfigs.GetLoadBetaTools() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("cpyversion"))
                {
                    if (arguments["<cpy_version>"] is null)
                    {
                        Console.WriteLine(string.Format("CPython version is set to: {0}",
                                                        PyRevitConfigs.GetCpythonEngineVersion()));
                    }
                    else
                    {
                        PyRevitConfigs.SetCpythonEngineVersion(int.Parse(TryGetValue("<cpy_version>")));
                    }
                }

                else if (all("usercanupdate"))
                {
                    if (any("yes", "no"))
                    {
                        PyRevitConfigs.SetUserCanUpdate(arguments["yes"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("User {0} update",
                                                        PyRevitConfigs.GetUserCanUpdate() ? "CAN" : "CAN NOT"));
                    }
                }

                else if (all("usercanextend"))
                {
                    if (any("yes", "no"))
                    {
                        PyRevitConfigs.SetUserCanExtend(arguments["yes"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("User {0} extend",
                                                        PyRevitConfigs.GetUserCanExtend() ? "CAN" : "CAN NOT"));
                    }
                }

                else if (all("usercanconfig"))
                {
                    if (any("yes", "no"))
                    {
                        PyRevitConfigs.SetUserCanConfig(arguments["yes"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("User {0} config",
                                                        PyRevitConfigs.GetUserCanConfig() ? "CAN" : "CAN NOT"));
                    }
                }

                else if (all("colordocs"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetColorizeDocs(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Doc Colorizer is {0}",
                                                        PyRevitConfigs.GetColorizeDocs() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("tooltipdebuginfo"))
                {
                    if (any("enable", "disable"))
                    {
                        PyRevitConfigs.SetAppendTooltipEx(arguments["enable"].IsTrue);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Doc Colorizer is {0}",
                                                        PyRevitConfigs.GetAppendTooltipEx() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("routes"))
                {
                    if (all("port"))
                    {
                        var portNumber = TryGetValue("<port_number>");
                        if (portNumber is null)
                        {
                            Console.WriteLine(string.Format("Routes Port: {0}", PyRevitConfigs.GetRoutesServerPort()));
                        }
                        else
                        {
                            PyRevitConfigs.SetRoutesServerPort(int.Parse(portNumber));
                        }
                    }

                    else if (all("coreapi"))
                    {
                        if (all("enable"))
                        {
                            PyRevitConfigs.SetRoutesLoadCoreAPIStatus(true);
                        }
                        else if (all("disable"))
                        {
                            PyRevitConfigs.SetRoutesLoadCoreAPIStatus(false);
                        }
                        else
                        {
                            Console.WriteLine(string.Format("Routes Core API is {0}",
                                                            PyRevitConfigs.GetRoutesLoadCoreAPIStatus() ? "Enabled" : "Disabled"));
                        }
                    }

                    else if (all("enable"))
                    {
                        PyRevitConfigs.EnableRoutesServer();
                    }

                    else if (all("disable"))
                    {
                        PyRevitConfigs.DisableRoutesServer();
                    }

                    else
                    {
                        Console.WriteLine(string.Format("Routes Server is {0}",
                                                        PyRevitConfigs.GetRoutesServerStatus() ? "Enabled" : "Disabled"));
                    }
                }

                else if (all("telemetry"))
                {
                    if (all("utc"))
                    {
                        if (any("yes", "no"))
                        {
                            PyRevitConfigs.SetUTCStamps(arguments["yes"].IsTrue);
                        }
                        else
                        {
                            Console.WriteLine(PyRevitConfigs.GetUTCStamps() ? "Using UTC timestamps" : "Using Local timestamps");
                        }
                    }

                    else if (all("file"))
                    {
                        var destPath = TryGetValue("<dest_path>");
                        if (destPath is null)
                        {
                            Console.WriteLine(string.Format("Telemetry File Path: {0}", PyRevitConfigs.GetAppTelemetryFlags()));
                        }
                        else
                        {
                            PyRevitConfigs.EnableTelemetry(telemetryFileDir: destPath);
                        }
                    }

                    else if (all("server"))
                    {
                        var serverUrl = TryGetValue("<dest_path>");
                        if (serverUrl is null)
                        {
                            Console.WriteLine(string.Format("Telemetry Server Url: {0}", PyRevitConfigs.GetAppTelemetryFlags()));
                        }
                        else
                        {
                            PyRevitConfigs.EnableTelemetry(telemetryServerUrl: serverUrl);
                        }
                    }

                    else if (all("hooks"))
                    {
                        if (any("yes", "no"))
                        {
                            PyRevitConfigs.SetTelemetryIncludeHooks(arguments["yes"].IsTrue);
                        }
                        else
                        {
                            Console.WriteLine(PyRevitConfigs.GetTelemetryIncludeHooks() ? "Sending telemetry for hooks" : "Not sending telemetry for hooks");
                        }
                    }

                    else if (all("enable"))
                    {
                        PyRevitConfigs.EnableTelemetry();
                    }

                    else if (all("disable"))
                    {
                        PyRevitConfigs.DisableTelemetry();
                    }

                    else
                    {
                        Console.WriteLine(string.Format("Telemetry is {0}",
                                                        PyRevitConfigs.GetTelemetryStatus() ? "Enabled" : "Disabled"));
                        Console.WriteLine(string.Format("File Path: {0}", PyRevitConfigs.GetTelemetryFilePath()));
                        Console.WriteLine(string.Format("Server Url: {0}", PyRevitConfigs.GetTelemetryServerUrl()));
                    }
                }

                else if (all("apptelemetry"))
                {
                    if (all("flags"))
                    {
                        var flagsValue = TryGetValue("<flags>");
                        if (flagsValue is null)
                        {
                            Console.WriteLine(string.Format("App Telemetry Flags: {0}", PyRevitConfigs.GetAppTelemetryFlags()));
                        }
                        else
                        {
                            PyRevitConfigs.SetAppTelemetryFlags(flags: flagsValue);
                        }
                    }

                    else if (all("server"))
                    {
                        var serverPath = TryGetValue("<server_path>");
                        if (serverPath is null)
                        {
                            Console.WriteLine(string.Format("App Telemetry Server: {0}", PyRevitConfigs.GetAppTelemetryServerUrl()));
                        }
                        else
                        {
                            PyRevitConfigs.EnableAppTelemetry(apptelemetryServerUrl: serverPath);
                        }
                    }

                    else if (all("enable"))
                    {
                        PyRevitConfigs.EnableAppTelemetry();
                    }

                    else if (all("disable"))
                    {
                        PyRevitConfigs.DisableAppTelemetry();
                    }

                    else
                    {
                        Console.WriteLine(string.Format("App Telemetry is {0}",
                                                        PyRevitConfigs.GetAppTelemetryStatus() ? "Enabled" : "Disabled"));
                        Console.WriteLine(string.Format("Server Url: {0}", PyRevitConfigs.GetAppTelemetryServerUrl()));
                        Console.WriteLine(string.Format("App Telemetry flag is {0}",
                                                        PyRevitConfigs.GetAppTelemetryFlags()));
                    }
                }

                else if (all("outputcss"))
                {
                    if (arguments["<css_path>"] is null)
                    {
                        Console.WriteLine(string.Format("Output Style Sheet is set to: {0}",
                                                        PyRevitConfigs.GetOutputStyleSheet()));
                    }
                    else
                    {
                        PyRevitConfigs.SetOutputStyleSheet(TryGetValue("<css_path>"));
                    }
                }

                else if (all("seed"))
                {
                    PyRevitConfigs.SeedConfig(makeCurrentUserAsOwner: arguments["--lock"].IsTrue);
                }

                else if (any("enable", "disable"))
                {
                    if (arguments["<option_path>"] != null)
                    {
                        // extract section and option names
                        string orignalOptionValue = TryGetValue("<option_path>");
                        if (orignalOptionValue.Split(':').Count() == 2)
                        {
                            string configSection = orignalOptionValue.Split(':')[0];
                            string configOption  = orignalOptionValue.Split(':')[1];

                            var cfg = PyRevitConfigs.GetConfigFile();
                            cfg.SetValue(configSection, configOption, arguments["enable"].IsTrue);
                        }
                        else
                        {
                            PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Main);
                        }
                    }
                }

                else
                {
                    if (arguments["<option_path>"] != null)
                    {
                        // extract section and option names
                        string orignalOptionValue = TryGetValue("<option_path>");
                        if (orignalOptionValue.Split(':').Count() == 2)
                        {
                            string configSection = orignalOptionValue.Split(':')[0];
                            string configOption  = orignalOptionValue.Split(':')[1];

                            var cfg = PyRevitConfigs.GetConfigFile();

                            // if no value provided, read the value
                            var optValue = TryGetValue("<option_value>");
                            if (optValue != null)
                            {
                                cfg.SetValue(configSection, configOption, optValue);
                            }
                            else if (optValue is null)
                            {
                                var existingVal = cfg.GetValue(configSection, configOption);
                                if (existingVal != null)
                                {
                                    Console.WriteLine(string.Format("{0} = {1}", configOption, existingVal));
                                }
                                else
                                {
                                    Console.WriteLine(string.Format("Configuration key \"{0}\" is not set", configOption));
                                }
                            }
                        }
                        else
                        {
                            PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Main);
                        }
                    }
                }
            }

            else if (all("doctor"))
            {
                if (IsHelpMode)
                {
                    PyRevitCLIAppCmds.RunDoctor("--wrappedhelp");
                }

                else if (TryGetValue("<doctor_command>") is var doctorCommand && doctorCommand != null)
                {
                    PyRevitCLIAppCmds.RunDoctor(doctorCommand, dryRun: arguments["--dryrun"].IsTrue);
                }

                else if (all("doctor", "--list"))
                {
                    PyRevitCLIAppCmds.RunDoctor("--list");
                }

                else
                {
                    PyRevitCLIAppCmds.RunDoctor("");
                }
            }
Ejemplo n.º 19
0
 PrintCloneInfo(string cloneName)
 {
     PyRevitCLIAppCmds.PrintHeader("Clone info");
     Console.WriteLine(PyRevitClones.GetRegisteredClone(cloneName));
 }
Ejemplo n.º 20
0
        RunPythonCommand(string inputCommand, string targetFile, string revitYear, PyRevitRunnerOptions runOptions)
        {
            // determine if script or command

            var modelFiles = new List <string>();

            // make sure file exists
            if (targetFile != null)
            {
                CommonUtils.VerifyFile(targetFile);
            }

            if (inputCommand != null)
            {
                // determine target revit year
                int revitYearNumber = 0;
                // if revit year is not specified try to get from model file
                if (revitYear is null)
                {
                    if (targetFile != null)
                    {
                        try {
                            revitYearNumber = new RevitModelFile(targetFile).RevitProduct.ProductYear;
                            // collect model names also
                            modelFiles.Add(targetFile);
                        }
                        catch (Exception ex) {
                            logger.Error(
                                "Revit version must be explicitly specifies if using a model list file. | {0}",
                                ex.Message
                                );
                        }
                    }
                    // if no revit year and no model, run with latest revit
                    else
                    {
                        revitYearNumber = RevitProduct.ListInstalledProducts().Max(r => r.ProductYear);
                    }
                }
                // otherwise, grab the year from argument
                else
                {
                    revitYearNumber = int.Parse(revitYear);
                    // prepare model list of provided
                    if (targetFile != null)
                    {
                        try {
                            var modelVer = new RevitModelFile(targetFile).RevitProduct.ProductYear;
                            if (revitYearNumber < modelVer)
                            {
                                logger.Warn("Model is newer than the target Revit version.");
                            }
                            else
                            {
                                modelFiles.Add(targetFile);
                            }
                        }
                        catch {
                            // attempt at reading the list file and grab the model files only
                            foreach (var modelPath in File.ReadAllLines(targetFile))
                            {
                                if (CommonUtils.VerifyFile(modelPath))
                                {
                                    try {
                                        var modelVer = new RevitModelFile(modelPath).RevitProduct.ProductYear;
                                        if (revitYearNumber < modelVer)
                                        {
                                            logger.Warn("Model is newer than the target Revit version.");
                                        }
                                        else
                                        {
                                            modelFiles.Add(modelPath);
                                        }
                                    }
                                    catch {
                                        logger.Error("File is not a valid Revit file: \"{0}\"", modelPath);
                                    }
                                }
                                else
                                {
                                    logger.Error("File does not exist: \"{0}\"", modelPath);
                                }
                            }
                        }
                    }
                }

                // now run
                if (revitYearNumber != 0)
                {
                    // determine attached clone
                    var attachment = PyRevitAttachments.GetAttached(revitYearNumber);
                    if (attachment is null)
                    {
                        logger.Error("pyRevit is not attached to Revit \"{0}\". " +
                                     "Runner needs to use the attached clone and engine to execute the script.",
                                     revitYear);
                    }
                    else
                    {
                        // determine script to run
                        string commandScriptPath = null;

                        if (!CommonUtils.VerifyPythonScript(inputCommand))
                        {
                            logger.Debug("Input is not a script file \"{0}\"", inputCommand);
                            logger.Debug("Attempting to find run command matching \"{0}\"", inputCommand);

                            // try to find run command in attached clone being used for execution
                            // if not found, try to get run command from all other installed extensions
                            var targetExtensions = new List <PyRevitExtension>();
                            if (attachment.Clone != null)
                            {
                                targetExtensions.AddRange(attachment.Clone.GetExtensions());
                            }
                            targetExtensions.AddRange(PyRevitExtensions.GetInstalledExtensions());

                            foreach (PyRevitExtension ext in targetExtensions)
                            {
                                logger.Debug("Searching for run command in: \"{0}\"", ext.ToString());
                                if (ext.Type == PyRevitExtensionTypes.RunnerExtension)
                                {
                                    try {
                                        var cmdScript = ext.GetRunCommand(inputCommand);
                                        if (cmdScript != null)
                                        {
                                            logger.Debug("Run command matching \"{0}\" found: \"{1}\"",
                                                         inputCommand, cmdScript);
                                            commandScriptPath = cmdScript;
                                            break;
                                        }
                                    }
                                    catch {
                                        // does not include command
                                        continue;
                                    }
                                }
                            }
                        }
                        else
                        {
                            commandScriptPath = inputCommand;
                        }

                        // if command is not found, stop
                        if (commandScriptPath is null)
                        {
                            throw new PyRevitException(
                                      string.Format("Run command not found: \"{0}\"", inputCommand)
                                      );
                        }

                        // RUN!
                        var execEnv = PyRevitRunner.Run(
                            attachment,
                            commandScriptPath,
                            modelFiles,
                            runOptions
                            );

                        // print results (exec env)
                        PyRevitCLIAppCmds.PrintHeader("Execution Environment");
                        Console.WriteLine(string.Format("Execution Id: \"{0}\"", execEnv.ExecutionId));
                        Console.WriteLine(string.Format("Product: {0}", execEnv.Revit));
                        Console.WriteLine(string.Format("Clone: {0}", execEnv.Clone));
                        Console.WriteLine(string.Format("Engine: {0}", execEnv.Engine));
                        Console.WriteLine(string.Format("Script: \"{0}\"", execEnv.Script));
                        Console.WriteLine(string.Format("Working Directory: \"{0}\"", execEnv.WorkingDirectory));
                        Console.WriteLine(string.Format("Journal File: \"{0}\"", execEnv.JournalFile));
                        Console.WriteLine(string.Format("Manifest File: \"{0}\"", execEnv.PyRevitRunnerManifestFile));
                        Console.WriteLine(string.Format("Log File: \"{0}\"", execEnv.LogFile));
                        // report whether the env was purge or not
                        if (execEnv.Purged)
                        {
                            Console.WriteLine("Execution env is successfully purged.");
                        }

                        // print target models
                        if (execEnv.ModelPaths.Count() > 0)
                        {
                            PyRevitCLIAppCmds.PrintHeader("Target Models");
                            foreach (var modelPath in execEnv.ModelPaths)
                            {
                                Console.WriteLine(modelPath);
                            }
                        }

                        // print log file contents if exists
                        if (File.Exists(execEnv.LogFile))
                        {
                            PyRevitCLIAppCmds.PrintHeader("Execution Log");
                            Console.WriteLine(File.ReadAllText(execEnv.LogFile));
                        }
                    }
                }
            }
        }