public static async Task <int> Main(string[] args)
        {
            var verboseOptions = new VerboseOption(args);

            var builder = new HostBuilder()
                          .ConfigureServices(s => s.AddSingleton <IVerboseOptions>(verboseOptions))
                          .ConfigureServices(ConfigureServices);

            if (verboseOptions.Enabled)
            {
                builder.ConfigureLogging(b => b.AddConsole());
            }

            Logger.Setup(new SentryRemoteLogger()).WithDefaultTags("CLI");

            try
            {
                return(await builder.RunCommandLineApplicationAsync <RootCommand>(args));
            }
            catch (TargetInvocationException ex) when(ex.InnerException != null)
            {
                Logger.Instance.TrackError(new CommandLineException(ex.Message, ex));
                Console.WriteLine($@"Error: {ex.InnerException.Message}");
                return(ResultCodes.Error);
            }
            catch (Exception ex)
            {
                Logger.Instance.TrackError(new CommandLineException(ex.Message, ex));
                Console.WriteLine($@"Error: {ex.Message}");
                return(ResultCodes.Error);
            }
        }
        public OpenTelemetryLogsFolderCommand() : base("OpenTelemetryLogsFolder", "opens the folder that contains the telemetry log files")
        {
            var telLogFolderPath = this.Option("-p|--path", $"opens the folder that contains the telemetry log files. Default value: '{KnownStrings.TelemetryLogFolder}'", CommandOptionType.SingleOrNoValue);

            this.OnExecute(async() => {
                var folderFullpath = telLogFolderPath.HasValue()
                    ? new PathHelper().GetFullPath(telLogFolderPath.Value())
                    : new PathHelper().GetFullPath(KnownStrings.TelemetryLogFolder);

                var openCommand = new CliCommand {
                    Command   = "open",
                    Arguments = folderFullpath
                };

                if (VerboseOption.HasValue())
                {
                    Console.WriteLine($"Opening telemetry log folder {folderFullpath}");
                }

                var cmdresult = await openCommand.RunCommand();
                if (!string.IsNullOrEmpty(cmdresult.StandardError))
                {
                    Console.WriteLine($"Error: {cmdresult.StandardError}");
                }
            });
        }
示例#3
0
        public static int Main(string[] args)
        {
            var verboseOptions = new VerboseOption(args);

            var builder = new HostBuilder()
                          .ConfigureServices(s => s.AddSingleton <IVerboseOptions>(verboseOptions))
                          .ConfigureServices(ConfigureServices);

            if (verboseOptions.Enabled)
            {
                builder.ConfigureLogging(b => b.AddConsole());
            }

            try
            {
                return(builder
                       .RunCommandLineApplicationAsync <RootCommand>(args)
                       .GetAwaiter()
                       .GetResult());
            }
            catch (TargetInvocationException ex) when(ex.InnerException != null)
            {
                Console.WriteLine($@"Error: {ex.InnerException.Message}");
                return(ResultCodes.Error);
            }
            catch (Exception ex)
            {
                Console.WriteLine($@"Error: {ex.Message}");
                return(ResultCodes.Error);
            }
        }
        public CompressLogsCommand() :
            base("CompressLogs",
                 "This will create a .zip of the existing log files. The file will be created by default in the log directory")
        {
            // command options
            var optionLogFolderPath = this.Option(
                "-l|--logfolderroot <PATH>",
                $"defines that path to the root folder containg the log files. Default value: '{KnownStrings.VsmacLogsFolderPath}'",
                CommandOptionType.SingleValue);

            var optionVersionNumber = Option(
                "-v|--version <VERSION>",
                "version number for VSMac [7.0 or 8.0]",
                CommandOptionType.SingleValue);

            optionVersionNumber.Validators.Add(new VsmacVersionValidator());

            var optionDestFilename = Option(
                "-f|--filename",
                "defines the filename of the log file that will be created. Default filename has a timestamp and version.",
                CommandOptionType.SingleValue);

            this.OnExecute(() => {
                string logfolder = optionLogFolderPath.HasValue()
                    ? new PathHelper().GetFullPath(optionLogFolderPath.Value())
                    : new PathHelper().GetFullPath(KnownStrings.VsmacLogsFolderPath);

                string version = optionVersionNumber.HasValue()
                    ? optionVersionNumber.Value()
                    : KnownStrings.DefaultVsmacVersion;

                if (!Directory.Exists(logfolder))
                {
                    throw new DirectoryNotFoundException($"log directory not found at {logfolder}");
                }

                string destfilename = optionDestFilename.HasValue()
                    ? optionDestFilename.Value()
                    : $"ide-{version}-log-{DateTime.Now.ToString("yyyy.MM.dd.ss.ff")}.zip";

                if (VerboseOption.HasValue())
                {
                    Console.WriteLine($@"CompressLogFiles called with
    folder:    '{logfolder}'
    version:   '{version}'
    filename:  '{destfilename}'");
                }

                if (VerboseOption.HasValue())
                {
                    Console.WriteLine("Creating zip file now");
                }

                System.IO.Compression.ZipFile.CreateFromDirectory(
                    Path.Combine(logfolder, version),
                    Path.Combine(logfolder, destfilename));
                Console.WriteLine($"Zip file created at {Path.Combine(logfolder, destfilename)}");
            });
        }
示例#5
0
        public CleanLogsCommand() : base("CleanLogs", "This will clean the log folder")
        {
            // command options
            var optionLogFolderPath = this.Option(
                "-l|--logfolderroot <PATH>",
                $"defines that path to the root folder containg the log files. Default value: '{KnownStrings.VsmacLogsFolderPath}'",
                CommandOptionType.SingleValue);

            var optionVersionNumber = Option(
                "-v|--version <VERSION>",
                "version number for VSMac [7.0 or 8.0]",
                CommandOptionType.SingleValue);

            optionVersionNumber.Validators.Add(new VsmacVersionValidator());

            this.OnExecute(() => {
                var logFolderRootPath = optionLogFolderPath.HasValue()
                    ? optionLogFolderPath.Value()
                    : new PathHelper().GetFullPath(KnownStrings.VsmacLogsFolderPath);

                var versionNumber = optionVersionNumber.HasValue()
                    ? optionVersionNumber.Value()
                    : "8.0";

                if (VerboseOption.HasValue())
                {
                    Console.WriteLine($"CleanLogFolder called with:\n\tlogFolderRootPath:\t{logFolderRootPath}\n\tversionNumber:\t\t{versionNumber}");
                }

                var logfolderfullpath = Path.GetFullPath(Path.Combine(logFolderRootPath, versionNumber));

                var filesToDelete = Directory.GetFiles(logfolderfullpath, "*", SearchOption.TopDirectoryOnly);

                if (filesToDelete.Length > 0)
                {
                    if (VerboseOption.HasValue())
                    {
                        Console.WriteLine("Deleting the following files:");
                    }

                    foreach (var file in filesToDelete)
                    {
                        if (VerboseOption.HasValue())
                        {
                            Console.WriteLine($"\t{file}");
                        }
                        File.Delete(file);
                    }
                }
                else
                {
                    Console.WriteLine($"No files to delete in folder: {logfolderfullpath}");
                }
            });
        }
示例#6
0
        public CleanTelemetryLogsCommand() : base("CleanTelemetryLogs", "removes the telemetry log files")
        {
            var optionTelFolderPath = Option("-p|--folderPath", "path to the folder that contains log files that will be deleted", CommandOptionType.SingleValue);

            this.OnExecute(() => {
                var telFolderFullPath = optionTelFolderPath.HasValue()
                    ? new PathHelper().GetFullPath(optionTelFolderPath.Value())
                    : new PathHelper().GetFullPath(KnownStrings.VsmacLogsFolderPath);

                if (!Directory.Exists(telFolderFullPath))
                {
                    Console.WriteLine($"Folder not found at: '{telFolderFullPath}'");
                    return;
                }

                var filesToDelete = Directory.GetFiles(telFolderFullPath, "*", SearchOption.TopDirectoryOnly);
                if (filesToDelete.Length <= 0)
                {
                    Console.WriteLine("Folder is empty");
                }
                else
                {
                    if (VerboseOption.HasValue())
                    {
                        Console.WriteLine($"Cleaning tel folder at: '{telFolderFullPath}'");
                    }

                    foreach (var file in filesToDelete)
                    {
                        var fileFullPath = Path.GetFullPath(file);
                        if (VerboseOption.HasValue())
                        {
                            Console.WriteLine($"Removing file {fileFullPath}");
                        }
                        File.Delete(fileFullPath);
                    }
                }
            });
        }