Exemple #1
0
        public ExitCode CreateShortcut(string destination, string shortcutName, bool force = false)
        {
            var result = ExitCode.NotStarted;
            var runner = new Runner();

            if (!force)
            {
                force = runner.GetForceOverwrite();
            }

            if (!string.IsNullOrEmpty(destination) &&
                !string.IsNullOrEmpty(shortcutName))
            {
                var args = new KeycutArgs(
                    destination,
                    shortcutName,
                    force: force);

                result = runner.Run(args);
            }
            else
            {
                result = ExitCode.BadArguments;
            }

            return(result);
        }
Exemple #2
0
        public static ExitCode Run(string[] args)
        {
            var result = ExitCode.NotStarted;

            var parsedArgs = Parser.Default.ParseArguments <Options>(args);

            if (!parsedArgs.Errors.Any())
            {
                var options = new Options
                {
                    Destination  = parsedArgs.Value.Destination?.Trim(),
                    Shortcut     = parsedArgs.Value.Shortcut?.Trim(),
                    OpenWithApp  = parsedArgs.Value.OpenWithApp?.Trim(),
                    OutputFolder = parsedArgs.Value.OutputFolder?.Trim(),
                    Force        = parsedArgs.Value.Force
                };

                if (options.Destination != null && options.Shortcut != null)
                {
                    var keycutArgs = new KeycutArgs(
                        options.Destination,
                        options.Shortcut,
                        options.OpenWithApp,
                        options.OutputFolder,
                        options.Force);

                    // Run app and pass arguments as parameters
                    var app = new Runner();
                    result = app.Run(keycutArgs);

                    if (result == ExitCode.FileAlreadyExists)
                    {
                        Console.WriteLine($"Shortcut file {options.Shortcut} already exists.");
                        Console.Write("Overwrite? (y / n)  ");
                        var overwriteInput = Console.ReadKey().KeyChar.ToString();
                        Console.WriteLine();

                        if (overwriteInput.ToLower() == "y")
                        {
                            // Force overwrite
                            keycutArgs.Force = true;
                            result           = app.Run(keycutArgs);
                        }
                    }
                }
                else
                {
                    // Show help text
                    Parser.Default.ParseArguments <Options>(new string[] { "--help" });
                    result = ExitCode.Success;
                }
            }

            return(result);
        }