Example #1
0
        public async Task <int> RunCommand(WebDAVLocation location, string directory = "")
        {
            if (!string.IsNullOrEmpty(location.Value))
            {
                _location = location;
            }

            if (!string.IsNullOrEmpty(directory))
            {
                directory         = directory.EndsWith("/") ? directory : directory + "/";
                _workingDirectory = new Uri("/" + directory, UriKind.Absolute);
            }

            _app = new CommandLineApplication {
                Name = ""
            };

            _app.HelpOption(inherited: true);

            _app.Command("ls", LsCommandHandler);
            _app.Command("lcd", LcdCommandHandler);
            _app.Command("cd", CdCommandHandler);
            _app.Command("get", GetCommandHandler);

            while (true)
            {
                DisplayPrompt();
                var cmd = _console.ReadLine();
                if (cmd == null)
                {
                    return(0);
                }
                try
                {
                    var result = await _app.ExecuteAsync(cmd.Split(" "));
                }

                catch (CommandParsingException ex)
                {
                    _console.Red("Invalid command.");
                    continue;
                }
            }

            return(0);
        }