Ejemplo n.º 1
0
        public void TestArgWithSingleQuotes()
        {
            string arg     = "'quotes'";
            string escaped = "\\'quotes\\'";

            Assert.AreEqual(escaped, StringUtils.Arg(arg));
            Assert.AreEqual(arg, StringUtils.UnArg(escaped));
        }
Ejemplo n.º 2
0
        public void TestArgWithSpaceAndSingleQuotes()
        {
            string arg     = "some 'arg with' spaces";
            string escaped = "\"some \\'arg with\\' spaces\"";

            Assert.AreEqual(escaped, StringUtils.Arg(arg));
            Assert.AreEqual(arg, StringUtils.UnArg(escaped));
        }
Ejemplo n.º 3
0
        public void TestArgWithQuotesAndSpaces()
        {
            string arg     = "spaces and \"quotes\"";
            string escaped = "\"spaces and \\\"quotes\\\"\"";

            Assert.AreEqual(escaped, StringUtils.Arg(arg));
            Assert.AreEqual(arg, StringUtils.UnArg(escaped));
        }
Ejemplo n.º 4
0
        public void TestArgWithSpace()
        {
            string arg     = "some arg with spaces";
            string escaped = '"' + arg + '"';

            Assert.AreEqual(escaped, StringUtils.Arg(arg));
            Assert.AreEqual(arg, StringUtils.UnArg(escaped));
        }
Ejemplo n.º 5
0
        public void TestArgWithNoSpace()
        {
            string arg     = "arg";
            string escaped = arg;

            Assert.AreEqual(escaped, StringUtils.Arg(arg));
            Assert.AreEqual(arg, StringUtils.UnArg(escaped));
        }
Ejemplo n.º 6
0
        void Execute(string prefix = null)
        {
            IList <CBinding> bindings = CBindings.List(prefix);

            foreach (CBinding b in bindings)
            {
                PrintIndent("bind {0} {1}", b.shortCut.ToString(), StringUtils.Arg(b.cmdKeyDown));
            }
        }
Ejemplo n.º 7
0
        private string GetOptionsUsage(List <Option> options)
        {
            if (options != null && options.Count > 0)
            {
                StringBuilder buffer = new StringBuilder();
                for (int i = 0; i < options.Count; ++i)
                {
                    Option opt = options[i];

                    buffer.Append(' ');

                    if (!opt.IsRequired)
                    {
                        buffer.Append('[');
                    }

                    if (opt.ShortName != null)
                    {
                        buffer.AppendFormat("-{0}|", StringUtils.C(opt.ShortName, ColorCode.TableVar));
                    }

                    buffer.AppendFormat("--{0}", StringUtils.C(opt.Name, ColorCode.TableVar));

                    if (opt.Type != typeof(bool))
                    {
                        if (opt.HasValues())
                        {
                            string[] values = opt.Values;
                            buffer.Append(" <");
                            for (int valueIndex = 0; valueIndex < values.Length; ++valueIndex)
                            {
                                buffer.Append(StringUtils.Arg(values[valueIndex]));
                                if (valueIndex < values.Length - 1)
                                {
                                    buffer.Append("|");
                                }
                            }
                            buffer.Append('>');
                        }
                        else
                        {
                            buffer.AppendFormat(" <{0}>", UsageOptionName(opt));
                        }
                    }

                    if (!opt.IsRequired)
                    {
                        buffer.Append(']');
                    }
                }

                return(buffer.ToString());
            }

            return(null);
        }
Ejemplo n.º 8
0
        public static string CreateCommandLine(string[] args, int startIndex = 0)
        {
            StringBuilder buffer = StringBuilderPool.NextAutoRecycleBuilder();

            for (int i = startIndex; i < args.Length; ++i)
            {
                buffer.Append(StringUtils.Arg(args[i]));
                if (i < args.Length - 1)
                {
                    buffer.Append(' ');
                }
            }

            return(buffer.ToString());
        }
Ejemplo n.º 9
0
        private static IList <string> ListCvars()
        {
            IList <CVar> cvars = CRegistery.ListVars(delegate(CVarCommand cmd)
            {
                return(!cmd.IsDefault && !cmd.HasFlag(CFlags.NoArchive));
            });

            IList <string> entries = new List <string>(cvars.Count);

            foreach (CVar cvar in cvars)
            {
                if (cvar.Value != null)
                {
                    entries.Add(string.Format("{0} {1}", cvar.Name, StringUtils.Arg(cvar.Value)));
                }
                else
                {
                    entries.Add("null " + cvar.Name);
                }
            }

            return(entries);
        }
Ejemplo n.º 10
0
 internal static string Arg(string value)
 {
     return(StringUtils.Arg(value));
 }
Ejemplo n.º 11
0
        bool Execute(string prefix = null)
        {
            CommandListOptions options = CCommand.DefaultListOptions;

            if (includeSystem)
            {
                options |= CommandListOptions.System;
            }

            // TODO: refactoring
            IList <CVar> vars = CRegistery.ListVars(prefix, options);

            if (vars.Count > 0)
            {
                if (shortList)
                {
                    string[] names = Collection.Map(vars, delegate(CVar cvar) {
                        return(StringUtils.C(cvar.Name, ColorCode.TableVar));
                    });
                    Print(names);
                }
                else
                {
                    StringBuilder result = new StringBuilder();
                    for (int i = 0; i < vars.Count; ++i)
                    {
                        CVar cvar = vars[i];
                        result.AppendFormat("  {0} {1}", StringUtils.C(cvar.Name, ColorCode.TableVar), StringUtils.Arg(cvar.Value));

                        // TODO: better color highlight
                        if (!cvar.IsDefault)
                        {
                            result.AppendFormat(" {0} {1}", StringUtils.C("default", ColorCode.TableVar), cvar.DefaultValue);
                        }

                        if (i < vars.Count - 1)
                        {
                            result.Append('\n');
                        }
                    }

                    Print(result.ToString());
                }
            }

            return(true);
        }
Ejemplo n.º 12
0
        private static IList <string> ListBindings()
        {
            IList <CBinding> bindings = CBindings.List();

            IList <string> entries = new List <string>(bindings.Count);

            foreach (CBinding binding in bindings)
            {
                entries.Add(string.Format("bind {0} {1}", binding.shortCut.ToString(), StringUtils.Arg(binding.cmdKeyDown)));
            }

            return(entries);
        }
Ejemplo n.º 13
0
 private static string ToString(CAliasCommand cmd)
 {
     return(string.Format("alias {0} {1}", cmd.Name, StringUtils.Arg(cmd.Alias)));
 }
Ejemplo n.º 14
0
 public static string ToString(CBinding b)
 {
     return(string.Format("bind {0} {1}", b.shortCut.ToString(), StringUtils.Arg(b.cmdKeyDown)));
 }