Esempio n. 1
0
        /// <summary>
        /// Opens console shell app. Usage:
        /// LiteDB.Shell [myfile.db] --param1 value1 --params2 "value 2"
        /// Parameters:
        /// --exec "command"   : Execute an shell command (can be multiples --exec)
        /// --run script.txt   : Run script commands file
        /// --pretty           : Show JSON in multiline + idented
        /// --upgrade newdb.db : Upgrade database to lastest version
        /// --exit             : Exit after last command
        /// </summary>
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            var input   = new InputCommand();
            var display = new Display();
            var o       = new OptionSet();

            // default arg
            o.Register((v) => input.Queue.Enqueue("open " + v));
            o.Register("pretty", () => display.Pretty = true);
            o.Register("exit", () => input.AutoExit   = true);
            o.Register <string>("run", (v) => input.Queue.Enqueue("run " + v));
            o.Register <string>("exec", (v) => input.Queue.Enqueue(v));
            o.Register <string>("upgrade", (v) =>
            {
                var tmp = Path.GetTempFileName();
                input.Queue.Enqueue("dump > " + tmp);
                input.Queue.Enqueue("open " + v);
                input.Queue.Enqueue("dump < " + tmp);
            });

            // parse command line calling register parameters
            o.Parse(args);

            ShellProgram.Start(input, display);
        }
Esempio n. 2
0
        public string ReadCommand()
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("> ");

            var cmd = this.ReadLine().Trim();

            // single line only for shell commands
            if (ShellProgram.GetCommand(cmd) == null)
            {
                while (!cmd.EndsWith(";"))
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("| ");

                    var line = this.ReadLine();
                    cmd += Environment.NewLine + line;
                }
            }

            cmd = cmd.Trim();

            this.History.Add(cmd);

            return(cmd.Trim());
        }
Esempio n. 3
0
        /// <summary>
        /// Opens console shell app. Usage:
        /// LiteDB.Shell [myfile.db] --param1 value1 --params2 "value 2"
        /// Parameters:
        /// --exec "command"   : Execute an shell command (can be multiples --exec)
        /// --run script.txt   : Run script commands file
        /// --pretty           : Show JSON in multiline + indented
        /// --exit             : Exit after last command
        /// </summary>
        private static void Main(string[] args)
        {
            var input   = new InputCommand();
            var display = new Display();
            var o       = new OptionSet();

            // default arg
            o.Register((v) => input.Queue.Enqueue("open " + v));
            o.Register("pretty", () => display.Pretty = true);
            o.Register("exit", () => input.AutoExit   = true);
            o.Register <string>("run", (v) => input.Queue.Enqueue("run " + v));
            o.Register <string>("exec", (v) => input.Queue.Enqueue(v));

            // parse command line calling register parameters
            o.Parse(args);

            ShellProgram.Start(input, display);
        }