コード例 #1
0
        static void Main(string[] args)
        {
            // Cmdr: A CommandLine Arguments Parser
            Cmdr.NewWorker(RootCmd.New(
                               new AppInfo {
                AppName = "mdx-tool",
            }, (root) =>
            {
                root.AddCommand(new Command
                {
                    Short    = "lkp", Long = "lookup", Description = "dictionary lookup tool",
                    TailArgs = "<Mdx Files (*.mdx;*.mdd)> <word-pattern>",
                    Action   = (lookupAction)
                });

                root.AddCommand(new Command
                {
                    Short       = "ls", Long = "list",
                    Description = "list a dictionary entries and dump for debugging",
                    TailArgs    = "<Mdx Files (*.mdx;*.mdd)>",
                    Action      = (listAction)
                });

                root.AddCommand(new Command {
                    Short = "t", Long = "tags", Description = "tags operations"
                }
                                .AddCommand(new TagsAddCmd())
                                .AddCommand(new TagsRemoveCmd())
                                // .AddCommand(new TagsAddCmd { }) // dup-test
                                .AddCommand(new TagsListCmd())
                                .AddCommand(new TagsModifyCmd())
                                );
            }),            // <- RootCmd
                           // Options ->
                           (w) =>
            {
                w.SetLogger(SerilogBuilder.Build((logger) =>
                {
                    logger.EnableCmdrLogInfo  = false;
                    logger.EnableCmdrLogTrace = false;
                }));

                // w.EnableDuplicatedCharThrows = true;
            })
            .Run(args);

            // HzNS.MdxLib.Core.Open("*.mdx,mdd,sdx,wav,png,...") => mdxfile
            // mdxfile.Preload()
            // mdxfile.GetEntry("beta") => entryInfo.{item,index}
            // mdxfile.Find("a")           // "a", "a*b", "*b"
            // mdxfile.Close()
            // mdxfile.Find()
            // mdxfile.Find()
            // mdxfile.Find()

            // Log.CloseAndFlush();
            // Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: hedzr/Cmdr.Core
        static void Main(string[] args)
        {
            var log = Log.Logger;

            log.Information("YES IT IS");

            // throw new Exception("sys");

            // Cmdr: A CommandLine Arguments Parser
            Cmdr.NewWorker(RootCommand.New(new AppInfo {
                AppName = "commander"
            }, (root) =>
            {
                root.AddCommand(new Command {
                    Short = "t", Long = "tags", Description = "tags operations"
                }
                                .AddCommand(new TagsAddCmd())
                                .AddCommand(new TagsRemoveCmd())
                                // .AddCommand(new TagsAddCmd { }) // dup-test
                                .AddCommand(new TagsListCmd())
                                .AddCommand(new TagsModifyCmd())
                                );
            }),         // <- RootCmd
                        // Options ->
                           (w) =>
            {
                //
                // w.UseSerilog((configuration) => configuration.WriteTo.Console().CreateLogger())
                //
                w.SetLogger(SerilogBuilder.Build((logger) =>
                {
                    logger.EnableCmdrLogInfo  = false;
                    logger.EnableCmdrLogTrace = false;
                }));

                // w.EnableDuplicatedCharThrows = true;
            })
            .Run(args);

            // HzNS.MdxLib.Core.Open("*.mdx,mdd,sdx,wav,png,...") => mdxfile
            // mdxfile.Preload()
            // mdxfile.GetEntry("beta") => entryInfo.{item,index}
            // mdxfile.Find("a")           // "a", "a*b", "*b"
            // mdxfile.Close()
            // mdxfile.Find()
            // mdxfile.Find()
            // mdxfile.Find()

            // Log.CloseAndFlush();
            // Console.ReadKey();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: hedzr/Cmdr.Core
        // static void Main(string[] args)
        // {
        //     Console.WriteLine("Hello World!");
        // }
        // ReSharper disable once ArrangeTypeMemberModifiers
        static int Main(string[] args)
        {
            log = new LoggerConfiguration()
                  .MinimumLevel.Debug()
                  .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                  .Enrich.FromLogContext()
                  .Enrich.WithCaller()
                  .WriteTo.Console(
                outputTemplate:
                "[{Timestamp:HH:mm:ss} {Level:u3}] {Message} (at {Caller} in {SourceFileName}:line {SourceFileLineNumber}){NewLine}{Exception}")
                  // .WriteTo.File(Path.Combine("logs", @"access.log"), rollingInterval: RollingInterval.Day)
                  // .WriteTo.Console()
                  .CreateLogger();
            var loggerWrapper = HzNS.Cmdr.Logger.Serilog.SerilogBuilder.Build((logger) =>
            {
                // logger.EnableCmdrLogInfo = true;
                // logger.EnableCmdrLogTrace = true;
            });

            return(Cmdr.Compile <SampleAttrApp>(args, loggerWrapper,
                                                (w) => w.SetLogger(loggerWrapper)));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: hedzr/Cmdr.Core
        static int Main(string[] args) => Cmdr.NewWorker(

            #region RootCmd Definitions

            SimpleRootCmd.New(
                new AppInfo
        {
            AppName = "tag-tool",
            // AppVersion = "v1.0.0",
            Author    = "hedzr",
            Copyright = "Copyright © Hedzr Studio, 2020. All Rights Reserved.",
        },
                (root) =>
        {
            root.Description     = "description here";
            root.DescriptionLong = "long description here";
            root.Examples        = "examples here";

            // for "dz"
            _a = 0;

            root.AddCommand(new Command
            {
                Short = "t", Long = "test", Description = "test command",
            }
                            +new Flag <Uri> {
                Long = "uri", Description = "URI"
            }
                            +new Flag <TimeSpan>
            {
                Long = "time-span", Short = "ts", Description = "TimeSpan",
                UseMomentTimeFormat = true,
            }
                            +new Flag <Direction>
            {
                Long = "direction", Short = "dir", Description = "Direction",
                UseMomentTimeFormat = true,
            }
                            );

            root.AddCommand(new Command
            {
                Short  = "dz", Long = "dz", Description = "test divide by zero",
                Action = (worker, opt, remainArgs) => { Console.WriteLine($"{B / _a}"); },
            })
            .AddCommand(new Command {
                Short = "t", Long = "tags", Description = "tags operations"
            }
                        .AddCommand(new TagsAddCmd())
                        .AddCommand(new TagsRemoveCmd())
                        // .AddCommand(new TagsAddCmd { }) // for dup-test
                        .AddCommand(new TagsListCmd())
                        .AddCommand(new TagsModifyCmd())
                        .AddCommand(new TagsModeCmd())
                        .AddCommand(new TagsToggleCmd())
                        .AddFlag(new Flag <string>
            {
                DefaultValue = "consul.ops.local",
                Long         = "addr", Short = "a", Aliases = new[] { "address", "host" },
                Description  =
                    "Consul IP/Host and/or Port: HOST[:PORT] (No leading 'http(s)://')",
                PlaceHolder = "HOST[:PORT]",
                Group       = "Consul",
            })
                        .AddFlag(new Flag <string>
            {
                DefaultValue = "",
                // ReSharper disable once StringLiteralTypo
                Long        = "cacert", Short = "", Aliases = new string[] { "ca-cert" },
                Description = "Consul Client CA cert)",
                PlaceHolder = "FILE",
                Group       = "Consul",
            })
                        .AddFlag(new Flag <string>
            {
                DefaultValue = "",
                Long         = "cert", Short = "", Aliases = new string[] { },
                Description  = "Consul Client Cert)",
                PlaceHolder  = "FILE",
                Group        = "Consul",
            })
                        .AddFlag(new Flag <bool>
            {
                DefaultValue = false,
                Long         = "insecure", Short = "k", Aliases = new string[] { },
                Description  = "Ignore TLS host verification",
                Group        = "Consul",
            })
                        )
            .AddCommand(new Command
            {
                Short  = "zm", Long = "zm", Description = "test mazy",
                Action = (worker, opt, remainArgs) => { Console.WriteLine($"{B / _a}"); },
            });


            root.AddCommand(new ServerCmd());


            root.OnSet = (worker, flag, oldValue, newValue) =>
            {
                if (Cmdr.Instance.Store.GetAs <bool>("quiet"))
                {
                    return;
                }
                if (Cmdr.Instance.Store.GetAs <bool>("verbose") &&
                    flag.Root?.FindFlag("verbose")?.HitCount > 1)
                {
                    Console.WriteLine(
                        $"--> [{Cmdr.Instance.Store.GetAs<bool>("quiet")}][root.onSet] {flag} set: {oldValue?.ToStringEx()} -> {newValue?.ToStringEx()}");
                }
            };
        }
                ), // <- RootCmd Definitions

            #endregion

            #region Options for Worker

            (w) =>
        {
            w.SetLogger(HzNS.Cmdr.Logger.Serilog.SerilogBuilder.Build((logger) =>
            {
                // logger.EnableCmdrLogInfo = true;
                // logger.EnableCmdrLogTrace = true;
            }));

            w.EnableCmdrGreedyLongFlag = true;
            // w.EnableDuplicatedCharThrows = true;
            // w.EnableEmptyLongFieldThrows = true;

            w.RegisterExternalConfigurationsLoader(ExternalConfigLoader);

            w.OnDuplicatedCommandChar = (worker, command, isShort, matchingArg) => false;
            w.OnDuplicatedFlagChar    = (worker, command, flag, isShort, matchingArg) => false;
            w.OnCommandCannotMatched  = (parsedCommand, matchingArg) => false;
            w.OnFlagCannotMatched     = (parsingCommand, fragment, isShort, matchingArg) => false;
            w.OnSuggestingForCommand  = (worker, dataset, token) => false;
            w.OnSuggestingForFlag     = (worker, dataset, token) => false;
        }

            #endregion

            )
        .Run(args, () =>
        {
            // Wait for the user to quit the program.

            // Console.WriteLine($"         AssemblyVersion: {VersionUtil.AssemblyVersion}");
            // Console.WriteLine($"             FileVersion: {VersionUtil.FileVersion}");
            // Console.WriteLine($"    InformationalVersion: {VersionUtil.InformationalVersion}");
            // Console.WriteLine($"AssemblyProductAttribute: {VersionUtil.AssemblyProductAttribute}");
            // Console.WriteLine($"      FileProductVersion: {VersionUtil.FileVersionInfo.ProductVersion}");
            // Console.WriteLine();

            // Console.WriteLine("Press 'q' to quit the sample.");
            // while (Console.Read() != 'q')
            // {
            //     //
            // }

            return(0);
        });