示例#1
0
        public static void QuotedSwitchName()
        {
            var args = GitCmdArgs.Parse($"{ExeName} --swi\"tch\"");

            Assert.AreEqual(Exe, args.Exe);
            Assert.AreEqual(Name, args.Name);
            Assert.AreEqual(0, args.Length);
            Assert.IsTrue(args.IsSet("switch"));
        }
示例#2
0
        public static void SimpleNameTest()
        {
            var args = GitCmdArgs.Parse(ExeName);

            Assert.AreEqual(Exe, args.Exe);
            Assert.AreEqual(Name, args.Name);
            Assert.AreEqual(0, args.Length);
            Assert.AreEqual(0, args.Switches().Count());
        }
示例#3
0
        public static void SimpleSwitch()
        {
            var longArgs = GitCmdArgs.Parse($"{ExeName} --{LongSwitch}");

            Assert.IsTrue(longArgs.IsSet(LongSwitch.ToUpper()));
            Assert.IsTrue(longArgs.IsSet(LongSwitch.ToLower()));

            var shortArgs = GitCmdArgs.Parse($"{ExeName} -{ShortSwitch}");

            Assert.IsTrue(shortArgs.IsSet(ShortSwitch.ToUpper()));
            Assert.IsTrue(shortArgs.IsSet(ShortSwitch.ToLower()));
        }
示例#4
0
文件: LfxCmd.cs 项目: kingces95/lfx
        private GitCmdArgs Parse(
            int minArgs = 0,
            int maxArgs = int.MaxValue,
            IEnumerable <GitCmdSwitchInfo> switchInfo = null)
        {
            if (switchInfo == null)
            {
                switchInfo = GitCmdSwitchInfo.Create();
            }

            return(GitCmdArgs.Parse(m_commandLine, minArgs, maxArgs, switchInfo));
        }
示例#5
0
        public static void KnownSwitchEnum()
        {
            var args = GitCmdArgs.Parse(
                $"{ExeName} -{ShortSwitch} --{LongSwitch}",
                switchInfo: GitCmdSwitchInfo.Create(
                    KnownSwitches.MyGitSwitch,
                    KnownSwitches.M
                    )
                );

            Assert.IsTrue(args.IsSet(KnownSwitches.MyGitSwitch));
            Assert.IsTrue(args.IsSet(KnownSwitches.M));
        }
示例#6
0
        public static void UnknownSwitchName()
        {
            var switches = GitCmdSwitchInfo.Create(
                ShortSwitch,
                LongSwitch
                );

            var longSwitchCmd = $"{ExeName} --{OtherLongSwitch}";

            GitCmdArgs.Parse(longSwitchCmd);
            Throws(() => GitCmdArgs.Parse(longSwitchCmd, switchInfo: switches));

            var shortSwitchCmd = $"{ExeName} -{OtherShortSwitch}";

            GitCmdArgs.Parse(shortSwitchCmd);
            Throws(() => GitCmdArgs.Parse(shortSwitchCmd, switchInfo: switches));
        }
示例#7
0
文件: LfxCmd.cs 项目: kingces95/lfx
        private void Execute()
        {
            var bf =
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.IgnoreCase;

            try {
                var args = GitCmdArgs.Parse(m_commandLine);
                var name = args.Name;

                // default
                if (args.Name == null)
                {
                    Help();
                    return;
                }

                // check name
                var method = typeof(LfxCmd).GetMethod(name, bf);
                if (method == null)
                {
                    throw new GitCmdException($"Command '{name}' unrecognized.");
                }

                // dispach
                method.Invoke(this, null);
            } catch (TargetInvocationException tie) {
                var e = tie.InnerException;

                var ae = e as AggregateException;
                if (ae != null)
                {
                    e = ae.InnerException;
                }

                Log($"{e.GetType()}: {e.Message}");
            } catch (Exception e) {
                Log($"{e.GetType()}: {e.Message}");
            }
        }
示例#8
0
        public static void AllTypesTest()
        {
            var args = GitCmdArgs.Parse($"{ExeName} -{ShortSwitch} --{LongSwitch} \"{FileNameWithSpaces}\"");

            Assert.AreEqual(Exe, args.Exe);
            Assert.AreEqual(Name, args.Name);
            Assert.IsTrue(args.IsSet(LongSwitch));
            Assert.IsTrue(args.IsSet(ShortSwitch));
            Assert.IsTrue(args.IsSet(ShortSwitch, OtherShortSwitch));
            Assert.IsFalse(args.IsSet(OtherShortSwitch));
            Assert.AreEqual(FileNameWithSpaces, args.Single());
            Assert.AreEqual(FileNameWithSpaces, args[0]);
            Assert.AreEqual(1, args.Length);

            var toString = args.ToString();

            Assert.IsTrue(toString.Contains($"{Exe}"));
            Assert.IsTrue(toString.Contains($"{Name}"));
            Assert.IsTrue(toString.Contains($"{ShortSwitch.ToLower()}"));
            Assert.IsTrue(toString.Contains($"{LongSwitch.ToLower()}"));
            Assert.IsTrue(toString.Contains($"{FileNameWithSpaces}"));
        }
示例#9
0
 public static void ArgBoundsName()
 {
     GitCmdArgs.Parse($"{ExeName} a", minArgs: 1, maxArgs: 1);
     Throws(() => GitCmdArgs.Parse($"{ExeName} a b", minArgs: 1, maxArgs: 1));
     Throws(() => GitCmdArgs.Parse($"{ExeName}", minArgs: 1, maxArgs: 1));
 }
示例#10
0
 public static void ThrowsDuplicateSwitch()
 {
     Throws(() => GitCmdArgs.Parse($"{ExeName} -a -a"));
     Throws(() => GitCmdArgs.Parse($"{ExeName} --aa --aa"));
 }
示例#11
0
 public static void ThrowsBadSwitchLength()
 {
     Throws(() => GitCmdArgs.Parse($"{ExeName} --a"));
     Throws(() => GitCmdArgs.Parse($"{ExeName} -aa"));
 }
示例#12
0
 public static void ThrowsNoSwitchName()
 {
     Throws(() => GitCmdArgs.Parse($"{ExeName} -"));
     GitCmdArgs.Parse($"{ExeName} --");
 }
示例#13
0
 public static void ThrowsDasheCount()
 {
     Throws(() => GitCmdArgs.Parse($"{ExeName} ---a"));
 }
示例#14
0
 public static void ThrowsNoName()
 {
     Throws(() => GitCmdArgs.Parse($"--a"));
 }