예제 #1
0
        public static void Main(string[] args)
        {
            const string ShortOutput = "short";
            const string LongOutput  = "long";

            // set default values here
            string output    = null;
            bool   debug     = false;
            string path      = null;
            string value     = null;
            int    threshold = 0;

            var configuration = CommandLineParserConfigurator
                                .Create()
                                .WithNamed("o", v => output = v)
                                .HavingLongAlias("output")
                                .Required()
                                .RestrictedTo(ShortOutput, LongOutput)
                                .DescribedBy("method", "specifies the output method.")
                                .WithNamed("t", (int v) => threshold = v)
                                .HavingLongAlias("threshold")
                                .DescribedBy("value", "specifies the threshold used in output.")
                                .WithSwitch("d", () => debug = true)
                                .HavingLongAlias("debug")
                                .DescribedBy("enables debug mode")
                                .WithPositional(v => path = v)
                                .Required()
                                .DescribedBy("path", "path to the output file.")
                                .WithPositional(v => value = v)
                                .DescribedBy("value", "some optional value.")
                                .BuildConfiguration();

            var parser = new CommandLineParser(configuration);

            var parseResult = parser.Parse(args);

            if (!parseResult.Succeeded)
            {
                Usage usage = new UsageComposer(configuration).Compose();
                Console.WriteLine(parseResult.Message);
                Console.WriteLine("usage:" + usage.Arguments);
                Console.WriteLine("options");
                Console.WriteLine(usage.Options.IndentBy(4));
                Console.WriteLine();

                return;
            }

            Console.WriteLine("parsed successfully: path = " + path + ", value = " + value + "output = " + output + ", debug = " + debug + ", threshold = " + threshold);
        }
예제 #2
0
        public static int Main(string[] args)
        {
            string input = null;
            string output = null;

            var configuration = CommandLineParserConfigurator
                .Create()
                     .WithNamed("i", v => input = v)
                        .HavingLongAlias("input")
                        .Required()
                        .DescribedBy("path", "specifies the input path pointing to a xBehave/xUnit XML report.")
                    .WithNamed("o", v => output = v)
                        .HavingLongAlias("output")
                        .Required()
                        .DescribedBy("path", "specifies the output path where the generated markdown will be written to.")
                .BuildConfiguration();

            var parser = new CommandLineParser(configuration);
            var parseResult = parser.Parse(args);

            if (!parseResult.Succeeded)
            {
                Usage usage = new UsageComposer(configuration).Compose();
                Console.WriteLine(parseResult.Message);
                Console.WriteLine("usage:" + usage.Arguments);
                Console.WriteLine("options");
                Console.WriteLine(usage.Options.IndentBy(4));
                Console.WriteLine();
                return InvalidFunction;
            }

            if (!File.Exists(input))
            {
                Console.WriteLine("Input file '{0}' does not exist, please define an existing file.", input);
                return FileNotFound;
            }

            var inputXml = XDocument.Load(input);

            var converter = new Converter();

            var outputMarkdown = converter.Convert(inputXml);

            using (var writer = new StreamWriter(output))
            {
                writer.Write(outputMarkdown);
            }

            return Ok;
        }
예제 #3
0
        public void UnknownArgument(
            string[] args,
            CommandLineConfiguration configuration,
            UsageComposer usageComposer,
            Usage usage)
        {
            "establish a parsing configuration"._(() =>
            {
                configuration = CommandLineParserConfigurator
                                .Create()
                                .WithNamed("optional", _)
                                .DescribedBy("placeholder", "optional description")
                                .WithNamed("required", _)
                                .Required()
                                .DescribedBy("placeholder", "required description")
                                .BuildConfiguration();
            });

            "establish a usage composer using the parsing configuration"._(() =>
            {
                usageComposer = new UsageComposer(configuration);
            });

            "when composing usage"._(() =>
                                     usage = usageComposer.Compose());

            "should list arguments"._(() =>
                                      usage.Arguments
                                      .Should().Contain("-optional <placeholder>")
                                      .And.Contain("-required <placeholder>"));

            "should show whether an argument is optional or required"._(() =>
                                                                        (usage.Arguments + " ")
                                                                        .Should().Contain("[-optional <placeholder>]")
                                                                        .And.Contain(" -required <placeholder> "));

            "should list options per argument with description"._(() =>
                                                                  usage.Options
                                                                  .Should().Contain("optional description")
                                                                  .And.Contain("required description"));
        }
예제 #4
0
        static void Main(string[] args)
        {
            string username = null;
            string password = null;
            Outputs output = default(Outputs);
            IReadOnlyList<string> kompetenzen = null;
            string filter = null;
            LevelRange levelRange = new LevelRange { From = Level.Keyword, To = Level.Tool };
            Collection<Classification> classifications = new Collection<Classification>()
                                                             {
                                                                 Classification.Beherrschen,
                                                                 Classification.Beobachten,
                                                                 Classification.Experimentieren
                                                             };

            var configuration = CommandLineParserConfigurator
                .Create()
                    .WithNamed("u", v => username = v)
                        .Required()
                        .HavingLongAlias("username")
                        .DescribedBy("username", "username to access YouTrack")
                    .WithNamed("p", v => password = v)
                        .Required()
                        .HavingLongAlias("password")
                        .DescribedBy("password", "password to access YouTrack")
                    .WithNamed("o", v => output = ParseOutput(v))
                        .Required()
                        .HavingLongAlias("output")
                        .DescribedBy("output", "specifies what output to generate. Possible values: [tree, radar]")
                    .WithNamed("k", v => kompetenzen = ParseKompetenzen(v))
                        .HavingLongAlias("kompetenz")
                        .DescribedBy("kompetenzen", "comma separated list of Kompetenzen to include. All are included if not specified.")
                    .WithNamed("f", v => filter = v)
                        .DescribedBy("filter", "only elements related to elements matching the specified regex are included")
                    .WithNamed("l", v => levelRange = ParseLevelRange(v))
                        .DescribedBy("Levels", $"specify which levels to report in the format from..to with from and to one of [{Mappings.Of<Level>()}]. Default = K..T")
                    .WithNamed("c", v => classifications = ParseClassifications(v))
                        .DescribedBy("Klassifizierungen", $"comma seperated list of Klassifizierungen to include [{Mappings.Of<Classification>()}]. Default = {string.Join(",", classifications)}")
                    .BuildConfiguration();

            var parser = new CommandLineParser(configuration);
            ParseResult parseResult;
            try
            {
                parseResult = parser.Parse(args);
            }
            catch (Exception e)
            {
                parseResult = new ParseResult(false, e.Message);
            }

            // print usage if parsing failed
            if (!parseResult.Succeeded)
            {
                Usage usage = new UsageComposer(configuration).Compose();
                Console.WriteLine(parseResult.Message);
                Console.WriteLine("usage:" + usage.Arguments);
                Console.WriteLine("options");
                Console.WriteLine(usage.Options.IndentBy(4));
                Console.WriteLine();

                return;
            }

            try
            {
                Run(username, password, kompetenzen, filter, levelRange, classifications, output);
            }
            catch (AggregateException e)
            {
                var message = e.InnerExceptions.Aggregate(string.Empty, (a, v) => $"{a}{Environment.NewLine}{v.Message}");
                Console.WriteLine(message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #5
0
        private static void WriteUsageToConsole(CommandLineConfiguration commandLineConfiguration, ParseResult parseResult)
        {
            Usage usage = new UsageComposer(commandLineConfiguration).Compose();

            Console.WriteLine(parseResult.Message);
            Console.WriteLine("usage:" + usage.Arguments);
            Console.WriteLine("options");
            Console.WriteLine(usage.Options.IndentBy(4));
            Console.WriteLine();
        }
예제 #6
0
        private static void ShowUsage(CommandLineConfiguration configuration, string parseResult = "")
        {
            Usage usage = new UsageComposer(configuration).Compose();

            if (String.IsNullOrEmpty(parseResult))
            {
                var build = ((AssemblyInformationalVersionAttribute)Assembly
                              .GetAssembly(typeof(Program))
                              .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
                              .InformationalVersion;
                Console.WriteLine(@"
 ██▓███  ▓█████  ██▀███   ▄████▄   ██▓ ██▓███        ██▓ ▒█████  
▓██░  ██▒▓█   ▀ ▓██ ▒ ██▒▒██▀ ▀█  ▓██▒▓██░  ██▒     ▓██▒▒██▒  ██▒
▓██░ ██▓▒▒███   ▓██ ░▄█ ▒▒▓█    ▄ ▒██▒▓██░ ██▓▒     ▒██▒▒██░  ██▒
▒██▄█▓▒ ▒▒▓█  ▄ ▒██▀▀█▄  ▒▓▓▄ ▄██▒░██░▒██▄█▓▒ ▒     ░██░▒██   ██░
▒██▒ ░  ░░▒████▒░██▓ ▒██▒▒ ▓███▀ ░░██░▒██▒ ░  ░ ██▓ ░██░░ ████▓▒░
▒▓▒░ ░  ░░░ ▒░ ░░ ▒▓ ░▒▓░░ ░▒ ▒  ░░▓  ▒▓▒░ ░  ░ ▒▓▒ ░▓  ░ ▒░▒░▒░ 
░▒ ░      ░ ░  ░  ░▒ ░ ▒░  ░  ▒    ▒ ░░▒ ░      ░▒   ▒ ░  ░ ▒ ▒░ 
░░          ░     ░░   ░ ░         ▒ ░░░        ░    ▒ ░░ ░ ░ ▒  
            ░  ░   ░     ░ ░       ░             ░   ░      ░ ░  
                         ░                       ░               
Percip.io {0} - The working time logger by antic_eye ;)

Use this tool to track your productivity. MyLock generates an
encrypted database file that contains timestamps and ""in""
or ""out"".

When you call myLock with ""lock"" it tracks:
01.01.2016T08: 15 Max.Mustermann Out

When you call without args it tracks:
01.01.2016T08: 19 Max.Mustermann In

When you want to show your times, call it with ""--query"".It will
read the db and calculate your working time beginning with the
first ""in"" per day, ending with the last ""out"".

To automate the tracking, use ""--init"" and myLock will generate
Windows Scheduled tasks for screen lock/unlock and session
login/-out. You will need administrative permissions for this
task. Open an elevated command prompt.

", build);
                Console.WriteLine("Usage: percip.io.exe {0}", usage.Arguments);
                Console.WriteLine();
                Console.WriteLine(usage.Options);
                Console.WriteLine("Exit codes:");

                foreach (var e in Enum.GetValues(typeof(ExitCode)))
                    Console.WriteLine(string.Format("{0,4}\t{1}",
                        (int)e,
                        e.ToString()));
            }
            else
            {
                Console.WriteLine(parseResult);
                Console.WriteLine();
            }
        }
예제 #7
0
        public static int Main(string[] args)
        {
            string input  = null;
            string output = null;
            string markup = Markdown;

            var configuration = CommandLineParserConfigurator
                                .Create()
                                .WithNamed("i", v => input = v)
                                .HavingLongAlias("input")
                                .Required()
                                .DescribedBy("path", "specifies the input path pointing to a xBehave/xUnit XML report.")
                                .WithNamed("o", v => output = v)
                                .HavingLongAlias("output")
                                .Required()
                                .DescribedBy("path", "specifies the output path where the generated markdown will be written to.")
                                .WithNamed("m", v => markup = v)
                                .HavingLongAlias("markup")
                                .DescribedBy($"markup [{Markdown} | {DokuWiki}]", "specifies which markup to use")
                                .BuildConfiguration();

            var parser      = new CommandLineParser(configuration);
            var parseResult = parser.Parse(args);

            if (!parseResult.Succeeded)
            {
                Usage usage = new UsageComposer(configuration).Compose();
                Console.WriteLine(parseResult.Message);
                Console.WriteLine("usage:" + usage.Arguments);
                Console.WriteLine("options");
                Console.WriteLine(usage.Options.IndentBy(4));
                Console.WriteLine();
                return(InvalidFunction);
            }

            if (!File.Exists(input))
            {
                Console.WriteLine("Input file '{0}' does not exist, please define an existing file.", input);
                return(FileNotFound);
            }

            IMarkupWriter markupWriter;

            switch (markup.ToLowerInvariant())
            {
            case Markdown:
                markupWriter = new MarkdownWriter();
                break;

            case DokuWiki:
                markupWriter = new DokuWikiWriter();
                break;

            default:
                return(InvalidMarkup);
            }

            var inputXml = XDocument.Load(input);

            var converter = new Converter(markupWriter);

            var outputMarkdown = converter.Convert(inputXml);

            using (var writer = new StreamWriter(output))
            {
                writer.Write(outputMarkdown);
            }

            return(Ok);
        }
예제 #8
0
        private static void ShowUsage(CommandLineConfiguration configuration, string parseResult = "")
        {
            Usage usage = new UsageComposer(configuration).Compose();

            if (String.IsNullOrEmpty(parseResult))
            {
                var build = ((AssemblyInformationalVersionAttribute)Assembly
                             .GetAssembly(typeof(Program))
                             .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
                            .InformationalVersion;
                Console.WriteLine(@"
 ██▓███  ▓█████  ██▀███   ▄████▄   ██▓ ██▓███        ██▓ ▒█████  
▓██░  ██▒▓█   ▀ ▓██ ▒ ██▒▒██▀ ▀█  ▓██▒▓██░  ██▒     ▓██▒▒██▒  ██▒
▓██░ ██▓▒▒███   ▓██ ░▄█ ▒▒▓█    ▄ ▒██▒▓██░ ██▓▒     ▒██▒▒██░  ██▒
▒██▄█▓▒ ▒▒▓█  ▄ ▒██▀▀█▄  ▒▓▓▄ ▄██▒░██░▒██▄█▓▒ ▒     ░██░▒██   ██░
▒██▒ ░  ░░▒████▒░██▓ ▒██▒▒ ▓███▀ ░░██░▒██▒ ░  ░ ██▓ ░██░░ ████▓▒░
▒▓▒░ ░  ░░░ ▒░ ░░ ▒▓ ░▒▓░░ ░▒ ▒  ░░▓  ▒▓▒░ ░  ░ ▒▓▒ ░▓  ░ ▒░▒░▒░ 
░▒ ░      ░ ░  ░  ░▒ ░ ▒░  ░  ▒    ▒ ░░▒ ░      ░▒   ▒ ░  ░ ▒ ▒░ 
░░          ░     ░░   ░ ░         ▒ ░░░        ░    ▒ ░░ ░ ░ ▒  
            ░  ░   ░     ░ ░       ░             ░   ░      ░ ░  
                         ░                       ░               
Percip.io {0} - The working time logger by antic_eye ;)

Use this tool to track your productivity. MyLock generates an
encrypted database file that contains timestamps and ""in""
or ""out"".

When you call myLock with ""lock"" it tracks:
01.01.2016T08: 15 Max.Mustermann Out

When you call without args it tracks:
01.01.2016T08: 19 Max.Mustermann In

When you want to show your times, call it with ""--query"".It will
read the db and calculate your working time beginning with the
first ""in"" per day, ending with the last ""out"".

To automate the tracking, use ""--init"" and myLock will generate
Windows Scheduled tasks for screen lock/unlock and session
login/-out. You will need administrative permissions for this
task. Open an elevated command prompt.

", build);
                Console.WriteLine("Usage: percip.io.exe {0}", usage.Arguments);
                Console.WriteLine();
                Console.WriteLine(usage.Options);
                Console.WriteLine("Exit codes:");

                foreach (var e in Enum.GetValues(typeof(ExitCode)))
                {
                    Console.WriteLine(string.Format("{0,4}\t{1}",
                                                    (int)e,
                                                    e.ToString()));
                }
            }
            else
            {
                Console.WriteLine(parseResult);
                Console.WriteLine();
            }
        }