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")); }
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()); }
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())); }
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)); }
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)); }
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)); }
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}"); } }
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}")); }
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)); }
public static void ThrowsDuplicateSwitch() { Throws(() => GitCmdArgs.Parse($"{ExeName} -a -a")); Throws(() => GitCmdArgs.Parse($"{ExeName} --aa --aa")); }
public static void ThrowsBadSwitchLength() { Throws(() => GitCmdArgs.Parse($"{ExeName} --a")); Throws(() => GitCmdArgs.Parse($"{ExeName} -aa")); }
public static void ThrowsNoSwitchName() { Throws(() => GitCmdArgs.Parse($"{ExeName} -")); GitCmdArgs.Parse($"{ExeName} --"); }
public static void ThrowsDasheCount() { Throws(() => GitCmdArgs.Parse($"{ExeName} ---a")); }
public static void ThrowsNoName() { Throws(() => GitCmdArgs.Parse($"--a")); }