Example #1
0
        public static bool ParseOpts(string[] args, out Opts opts)
        {
            opts = null;
            bool showhelp = false;

            Opts tmpOpts = new Opts()
            {
            };
            var cmdOpts = new BeeOptsBuilder()
                          .Add('e', "err", OPTTYPE.VALUE, "filename for error messages", o => tmpOpts.errorFilename = o)
                          .Add('v', "verbose", OPTTYPE.BOOL, "show some debug output", o => tmpOpts.verbose         = true)
                          .Add('h', "help", OPTTYPE.BOOL, "show help", o => showhelp = true)
                          .GetOpts();

            tmpOpts.Filenames = BeeOpts.Parse(args, cmdOpts, (string unknownOpt) => Console.Error.WriteLine($"unknow option [{unknownOpt}]"));

            if (showhelp)
            {
                Console.WriteLine(
                    "\nusage: PXELogParser [OPTIONS] [Filenames...]"
                    + "\n\nOptions:");
                BeeOpts.PrintOptions(cmdOpts);
                return(false);
            }

            opts = tmpOpts;
            return(true);
        }
Example #2
0
        public static Opts Run(string[] args)
        {
            Opts opts = new Opts();

            bool showHelp        = false;
            var  CommandLineOpts = new BeeOptsBuilder()
                                   .Add('b', "base", OPTTYPE.VALUE, "basedir", (v) => opts.baseDir       = v)
                                   .Add('p', "path", OPTTYPE.BOOL, "create path", (v) => opts.createPath = true)
                                   .Add('h', "help", OPTTYPE.BOOL, "show this help", (v) => showHelp     = true)
                                   .GetOpts();

            IList <string> pargs = BeeOpts.Parse(args, CommandLineOpts, (optname) => Console.Error.WriteLine($"unknow option: [{optname}]"));

            if (showHelp)
            {
                opts = null;
                PrintUsage(CommandLineOpts);
            }
            else if (pargs.Count == 1)
            {
                opts.filename = pargs[0];
            }
            else
            {
                opts = null;
                PrintUsage(CommandLineOpts);
            }

            return(opts);
        }
Example #3
0
        public static Opts Parse(string[] args)
        {
            Opts opts = new Opts();

            bool            showHelp        = false;
            IList <BeeOpts> CommandLineOpts = new BeeOptsBuilder()
                                              .Add('d', "depth", OPTTYPE.VALUE, "max depth to go down", v => opts.Depth       = Convert.ToInt32(v))
                                              .Add('j', "follow", OPTTYPE.BOOL, "follow junctions", v => opts.FollowJunctions = (v != null))
                                              .Add('t', "threads", OPTTYPE.VALUE, "max enumeration threads parallel", v => opts.MaxThreads           = Convert.ToInt32(v))
                                              .Add('s', "same", OPTTYPE.BOOL, "report equal files (same.txt)", v => opts.reportSameFile              = true)
                                              .Add(null, "sorts", OPTTYPE.BOOL, "force sorting of entries on source side", v => opts.forceSortSource = true)
                                              .Add(null, "sortt", OPTTYPE.BOOL, "force sorting of entries on target side", v => opts.forceSortTarget = true)
                                              .Add('h', "help", OPTTYPE.BOOL, "show this help", v => showHelp = true)
                                              .GetOpts();

            IList <string> dirs = BeeOpts.Parse(
                args,
                CommandLineOpts,
                OnUnknown: (optname) => Console.Error.WriteLine($"unknow option: [{optname}]"));

            if (showHelp)
            {
                opts = null;
                PrintUsage(CommandLineOpts);
            }
            else
            {
                if (dirs.Count != 2)
                {
                    Console.Error.WriteLine("no two dir's given");
                    opts     = null;
                    showHelp = true;
                }
                else
                {
                    opts.sourceDir = dirs[0];
                    opts.targetDir = dirs[1];
                }

                if (opts != null && opts.forceSortSource)
                {
                    Console.Error.WriteLine("will sort items in source dir");
                }
                if (opts != null && opts.forceSortTarget)
                {
                    Console.Error.WriteLine("will sort items in target dir");
                }

                if (showHelp)
                {
                    Spi.BeeOpts.PrintOptions(CommandLineOpts);
                    opts = null;
                }
            }
            return(opts);
        }
Example #4
0
 private static void PrintUsage(IEnumerable <BeeOpts> CommandOpts)
 {
     Console.Error.WriteLine("Usage: CrtTree [OPTIONS] {filename}"
                             + "\ncreates directories given in {filename} line by line.\n"
                             + "\nDirectories (= lines in the textfile) will be sorted ascending by depth. (count of \"\\\")"
                             + "\nThen CreateDirectoryW() is called for each directory."
                             );
     Console.Error.WriteLine("\nOptions:");
     BeeOpts.PrintOptions(CommandOpts);
 }
Example #5
0
 private static void PrintUsage(IEnumerable <BeeOpts> CommandOpts)
 {
     Console.Error.WriteLine("Usage: CmpTrees [OPTIONS] {sourceDir} {targetDir}"
                             + "\ncompare two directore trees"
                             + "\n  new.txt ... exists only in source --> can be copied  to   target"
                             + "\n  del.txt ... exists only in target --> can be deleted from target"
                             + "\n  mod.txt ... exists in source AND target with the same name but different size or timestamp --> can be copied to target"
                             );
     Console.Error.WriteLine("\nOptions:");
     BeeOpts.PrintOptions(CommandOpts);
 }
Example #6
0
        public void NoOptions()
        {
            var opts = new BeeOptsBuilder()
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "a", "b" },
                opts,
                (optname) => throw new Exception($"unknow {optname}"));

            Assert.AreEqual(2, args.Count);
        }
Example #7
0
        public void OneOptionWithoutSpace()
        {
            string a = null;

            var opts = new BeeOptsBuilder()
                       .Add('a', "add", OPTTYPE.VALUE, "add more args", (v) => a = v)
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "-ab" },
                opts,
                (optname) => throw new Exception($"unknow {optname}"));

            Assert.AreEqual("b", a);
        }
Example #8
0
        public static bool ParseOpts(string[] args, out Opts opts)
        {
            opts = null;
            bool showhelp = false;

            Opts tmpOpts = new Opts()
            {
            };
            var cmdOpts = new BeeOptsBuilder()
                          .Add('m', "mac", OPTTYPE.VALUE, "mac address for ", o => tmpOpts.MAC = o)
                          .Add(null, "macfile", OPTTYPE.VALUE, "input file with MAC addresses", o => tmpOpts.FilenameMacAddresses = o)
                          .Add('s', "broadcast", OPTTYPE.VALUE, "IP address to send to", o => tmpOpts.broadcastIP = o)
                          .Add(null, "broadcastfile", OPTTYPE.VALUE, "input file with subnet broadcast IPs", o => tmpOpts.FilenameBroadcastIPs = o)
                          .Add('c', "cidr", OPTTYPE.VALUE, "CIDR of subnet", o => tmpOpts.cidr = o)
                          .Add(null, "cidrfile", OPTTYPE.VALUE, "input file with CIDRs", o => tmpOpts.FilenameCIDRs = o)
                          .Add('v', "verbose", OPTTYPE.BOOL, "show some output", o => tmpOpts.verbose = true)
                          .Add('h', "help", OPTTYPE.BOOL, "show help", o => showhelp = true)
                          .GetOpts();

            var parsedArgs = BeeOpts.Parse(args, cmdOpts, (string unknownOpt) => Console.Error.WriteLine($"unknow option [{unknownOpt}]"));

            if (String.IsNullOrEmpty(tmpOpts.MAC) && String.IsNullOrEmpty(tmpOpts.FilenameMacAddresses))
            {
                Console.Error.WriteLine("no MAC of file with MACs given");
                showhelp = true;
            }
            if (String.IsNullOrEmpty(tmpOpts.broadcastIP) && String.IsNullOrEmpty(tmpOpts.FilenameBroadcastIPs) &&
                String.IsNullOrEmpty(tmpOpts.cidr) && String.IsNullOrEmpty(tmpOpts.FilenameCIDRs))
            {
                tmpOpts.broadcastIP = "255.255.255.255";
                if (tmpOpts.verbose)
                {
                    Console.WriteLine($"setting broadcast IP to {tmpOpts.broadcastIP}");
                }
            }

            if (showhelp)
            {
                Console.WriteLine(
                    "\nusage: wol.exe [OPTIONS]"
                    + "\n\nOptions:");
                BeeOpts.PrintOptions(cmdOpts);
                return(false);
            }

            opts = tmpOpts;
            return(true);
        }
Example #9
0
        public void shortBoolOptionWithmoreThanOneChar()
        {
            bool          x = false;
            List <string> unknownOptions = new List <string>();

            var opts = new BeeOptsBuilder()
                       .Add('x', "req", OPTTYPE.BOOL, "desc", (v) => x = true)
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "-xbumsti" },
                opts,
                OnUnknown: (optname) => unknownOptions.Add(optname));

            Assert.IsTrue(x);
            CollectionAssert.AreEqual(new string[] { "b", "u", "m", "s", "t", "i" }.ToList(), unknownOptions);
        }
Example #10
0
        public void TwoValueOptions_one_not_given_other_order()
        {
            string r = null;
            string o = null;

            var opts = new BeeOptsBuilder()
                       .Add('r', "req", OPTTYPE.VALUE, "required", (v) => r = v)
                       .Add('o', "opt", OPTTYPE.VALUE, "optional", (v) => o = v)
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "-o", "-r", "r" },
                opts,
                (optname) => throw new Exception($"unknow {optname}"));

            Assert.AreEqual("r", r);
            Assert.IsNull(o);
        }
Example #11
0
        public void TwoOptions_long_short_with_value_2()
        {
            string r = null;
            string b = null;

            var opts = new BeeOptsBuilder()
                       .Add('r', "req", OPTTYPE.VALUE, "desc", (v) => r = v)
                       .Add('b', "boo", OPTTYPE.VALUE, "desc", (v) => b = v)
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "--boo", "huu", "-r", "R" },
                opts,
                (optname) => throw new Exception($"unknow option [{optname}]"));

            Assert.AreEqual("R", r);
            Assert.AreEqual("huu", b);
        }
Example #12
0
        public void TwoOptions_bool_value_long_notation()
        {
            string r = null;
            bool   b = false;

            var opts = new BeeOptsBuilder()
                       .Add('r', "req", OPTTYPE.VALUE, "desc", (v) => r = v)
                       .Add('b', "boo", OPTTYPE.BOOL, "desc", (v) => b  = true)
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "--boo", "-rR" },
                opts,
                (optname) => throw new Exception($"unknow option [{optname}]"));

            Assert.AreEqual("R", r);
            Assert.IsTrue(b);
        }
Example #13
0
        public static bool ParseOpts(string[] args, out Opts opts)
        {
            opts = null;
            bool showhelp = false;

            Opts tmpOpts = new Opts()
            {
            };
            var cmdOpts = new BeeOptsBuilder()
                          .Add('s', "SiteURL", OPTTYPE.VALUE, "Sharepoint site URL", o => tmpOpts.SiteURL       = o)
                          .Add('l', "list", OPTTYPE.VALUE, "name of the list to process", o => tmpOpts.listname = o)
                          .Add('h', "help", OPTTYPE.BOOL, "show help", o => showhelp = true)
                          .GetOpts();

            tmpOpts.command = BeeOpts.Parse(args, cmdOpts, (string unknownOpt) => Console.Error.WriteLine($"unknow option [{unknownOpt}]"));

            if (String.IsNullOrEmpty(tmpOpts.SiteURL))
            {
                showhelp = true;
                Console.Error.WriteLine("SiteURL is missing");
            }
            if (String.IsNullOrEmpty(tmpOpts.listname))
            {
                showhelp = true;
                Console.Error.WriteLine("name of the list is missing");
            }

            if (showhelp)
            {
                Console.WriteLine(
                    "\nusage: SPUtil.exe [OPTIONS] {command}"
                    + "\n\nOptions:");
                BeeOpts.PrintOptions(cmdOpts);
                Console.WriteLine(
                    "\nCommand:"
                    + "\n  l ........ list"
                    + "\n  d {id} ... delete item with {id}"
                    + "\n  da ....... delete all items");
                return(false);
            }

            opts = tmpOpts;
            return(true);
        }
Example #14
0
        public void unknowOption()
        {
            string r = "n/a";
            string b = null;

            var opts = new BeeOptsBuilder()
                       .Add('r', "req", OPTTYPE.VALUE, "desc", (v) => r = v)
                       .Add('b', "boo", OPTTYPE.VALUE, "desc", (v) => b = v)
                       .GetOpts();

            bool unknownOption = false;

            IList <string> args = BeeOpts.Parse(
                new string[] { "-j" },
                opts,
                OnUnknown: (optname) => unknownOption = true);

            Assert.IsTrue(unknownOption);
        }
Example #15
0
        public void shortBoolFollowedByValueInNextArg()
        {
            List <string> unknownOptions = new List <string>();

            bool   b   = false;
            string val = String.Empty;

            var opts = new BeeOptsBuilder()
                       .Add('b', "req", OPTTYPE.BOOL, "descb", (v) => b    = true)
                       .Add('v', "vvv", OPTTYPE.VALUE, "descv", (v) => val = v)
                       .GetOpts();

            IList <string> args = BeeOpts.Parse(
                new string[] { "-bv", "bumsti" },
                opts,
                OnUnknown: (optname) => unknownOptions.Add(optname));

            CollectionAssert.AreEqual(new string[] { }, unknownOptions);
            Assert.IsTrue(b);
            Assert.AreEqual("bumsti", val);
        }
Example #16
0
 static void ShowUsage(IEnumerable <BeeOpts> options)
 {
     Console.WriteLine("usage: pingp [OPTIONS] [filenameWithHostnames]\n");
     BeeOpts.PrintOptions(options);
 }