コード例 #1
0
        public void ResolveTest()
        {
            string n0  = "a";
            Usage  u0  = new Usage("usage");
            string v00 = "localhost";
            string v01 = "http://localhost";
            var    d   = new CommandArgProto(n0, u0, v01, new UrlValidator());

            Assert.Throws <ArgumentException>(() => d.Resolve(v00));
            Assert.True((Uri)d.Resolve(v01).ResolvedValue == new Uri(v01));
        }
コード例 #2
0
        public void ValidateTest()
        {
            string n0  = "a";
            Usage  u0  = new Usage("usage");
            string v00 = "1abc";
            string v01 = "abc1";
            var    d   = new CommandArgProto(n0, u0, null, new NameValidator());
            var    r00 = d.Validate(v00);
            var    r01 = d.Validate(v01);

            Assert.False(r00.Succeeded);
            Assert.True(r01.Succeeded);
        }
コード例 #3
0
        public void CtorTest()
        {
            string            n0 = "a";
            Usage             u0 = new Usage("usage");
            string            v0 = "b";
            CommandArgOptions o0 = CommandArgOptions.HasArgument
                                   | CommandArgOptions.HasMultiple
                                   | CommandArgOptions.IsRequired
                                   | CommandArgOptions.IsPositional;
            var d = new CommandArgProto(n0, u0, v0, null, o0);

            Assert.Equal(n0, d.Name);
            Assert.Equal(u0, d.Usage);
            Assert.Equal(v0, d.Value);
            Assert.Equal(o0, d.Options);
            Assert.True(d.IsRequired);
            Assert.True(d.HasMultiple);
            Assert.True(d.HasArgument);
            Assert.False(d.IsSwitch);
            Assert.True(d.IsPositional);
        }
コード例 #4
0
        public static void RegisterAll()
        {
            string programName = ProgramInfo.GetProgramName();
            var    filterArg   = new CommandArgProto(Names.FilterSwitch, Names.FilterMnemonic,
                                                     new Usage("Filter list of folders with expression",
                                                               new UsageWhere("exp", "Regular expression")),
                                                     null, null, CommandArgOptions.HasArgument);
            var positionArg = new CommandArgProto(Names.PositionSwitch, Names.PositionMnemonic,
                                                  new Usage("Starting position of folder", new UsageWhere("pos", "position of folder; default = 1")),
                                                  "1", new ValueValidator <int>(), CommandArgOptions.HasArgument);
            var lengthArg = new CommandArgProto(Names.LengthSwitch, Names.LengthMnemonic,
                                                new Usage("Number of path folders from position to include", new UsageWhere("len", "number of folders; default = 1")),
                                                "1", new ValueValidator <int>(), CommandArgOptions.HasArgument);
            var toArg = new CommandArgProto(Names.ToSwitch, Names.ToMnemonic,
                                            new Usage("Destination position for move", new UsageWhere("dpos", "1-based destination position")),
                                            "1", new ValueValidator <int>(), CommandArgOptions.HasArgument);
            var verboseArg = new CommandArgProto(Names.VerboseSwitch, Names.VerboseMnemonic, new Usage("Verbose output. Path elements in table with position and status."));
            var sortArg    = new CommandArgProto(Names.SortSwitch, CommandArgProto.NoMnemonic, new Usage("Sort output.  By default the order of the folder is as they appear in PATH"));
            var machineArg = new CommandArgProto(Names.MachineSwitch, Names.MachineMnemonic, new Usage("Use system PATH variable.  By default the local process path is used. Incompatible with -u (Windows only)"));
            var userArg    = new CommandArgProto(Names.UserSwitch, Names.UserMnemonic, new Usage("Use user PATH variable.  By default the local process path is used. Incompatible with -m (Windows only)"));
            var quietArg   = new CommandArgProto(Names.QuietSwitch, Names.QuietMnemonic, new Usage("Do not confirm operation.  Otherwise Y/N confirmation is required."));
            var inlineArg  = new CommandArgProto(Names.InlineSwitch, Names.InlineMnemonic, new Usage("Inline formating.  Creates output suitable for command execution.  Incompatible with -v"));

            CommandLineProtoRegistry.Instance.Register(new CommandLineProto(programName,
                                                                            new Usage(
                                                                                new UsageProto("pathtool list [--filter exp] [--verbose | --inline] [--machine | --user] [--sort]"),
                                                                                new UsageExample("pathtool -v", "List folders in path with position and validity")
                                                                                ),
                                                                            ListCommand,
                                                                            new CommandArgProto(Names.ListCommand, 1, new UsageCommand(Names.ListCommand, "List elements of path"), null, null, CommandArgOptions.IsCommand),
                                                                            filterArg,
                                                                            verboseArg,
                                                                            sortArg,
                                                                            machineArg,
                                                                            userArg,
                                                                            inlineArg
                                                                            ));
            CommandLineProtoRegistry.Instance.Register(new CommandLineProto(programName,
                                                                            new Usage(
                                                                                new UsageProto("pathtool clean [--machine | --user] [--quiet] [--verbose | --inline]"),
                                                                                new UsageExample("$env:PATH=$(pathtool clean -q)", "Clean PATH in local powershell"),
                                                                                new UsageExample("for /f \"delims=\" %i in ('pathtool clean -q') do PATH=%i", "Clean PATH in windows command shell")
                                                                                ),
                                                                            CleanCommand,
                                                                            new CommandArgProto(Names.CleanCommand, 1, new UsageCommand(Names.CleanCommand, "Clean path of invalid and duplicate elements"), null, null, CommandArgOptions.IsRequired | CommandArgOptions.IsCommand),
                                                                            quietArg,
                                                                            machineArg,
                                                                            userArg,
                                                                            verboseArg,
                                                                            inlineArg
                                                                            ));
            CommandLineProtoRegistry.Instance.Register(new CommandLineProto(programName,
                                                                            new UsageProto("pathtool add [--machine | --user] [--verbose | --inline] [--position pos] [--quiet] folder <folder> ..."),
                                                                            AddCommand,
                                                                            new CommandArgProto(Names.AddCommand, 1, new UsageCommand(Names.AddCommand, "Add folders to path"), null, null, CommandArgOptions.IsRequired | CommandArgOptions.IsCommand),
                                                                            machineArg,
                                                                            userArg,
                                                                            verboseArg,
                                                                            inlineArg,
                                                                            positionArg,
                                                                            quietArg,
                                                                            new CommandArgProto(Names.FolderArgument, 2, new UsageWhere(Names.FolderArgument, "Folder to add to path"), null, new FolderValidator(), CommandArgOptions.IsRequired | CommandArgOptions.HasMultiple)
                                                                            ));
            CommandLineProtoRegistry.Instance.Register(new CommandLineProto(programName,
                                                                            new UsageProto("pathtool remove [--machine | --user] [--verbose | --inline] [--position pos [--length len] | --filter exp] [--quiet]"),
                                                                            RemoveCommand,
                                                                            new CommandArgProto(Names.RemoveCommand, 1, new UsageCommand(Names.RemoveCommand, "Remove folders from path"), null, null, CommandArgOptions.IsRequired | CommandArgOptions.IsCommand),
                                                                            machineArg,
                                                                            userArg,
                                                                            verboseArg,
                                                                            inlineArg,
                                                                            positionArg,
                                                                            lengthArg,
                                                                            filterArg,
                                                                            quietArg
                                                                            ));
            CommandLineProtoRegistry.Instance.Register(new CommandLineProto(programName,
                                                                            new Usage(
                                                                                new UsageProto("pathtool move [--machine | --user] [--verbose | --inline] [--position pos] [--length len] [--distance dist] [--quiet]"),
                                                                                new UsageExample("pathtool move -pt 15 1", "move folder at position 15 to first in PATH")
                                                                                ),
                                                                            MoveCommand,
                                                                            new CommandArgProto(Names.MoveCommand, 1, new UsageCommand(Names.MoveCommand, "Move folders within PATH"), null, null, CommandArgOptions.IsRequired | CommandArgOptions.IsCommand),
                                                                            machineArg,
                                                                            userArg,
                                                                            verboseArg,
                                                                            inlineArg,
                                                                            positionArg,
                                                                            lengthArg,
                                                                            toArg,
                                                                            quietArg
                                                                            ));
        }