Ejemplo n.º 1
0
        public async Task RunAsync(CancellationToken token)
        {
            Console.WriteLine("This will connect to the PoshGit2 daemon process");
            Console.WriteLine();
            Console.WriteLine("Available commands:");
            Console.WriteLine("\t[path]     Search for a repo");
            Console.WriteLine("\t#q         Quit the loop");
            Console.WriteLine("\t#remove    Remove a repo from the cache");
            Console.WriteLine("\t#all       Retrieve all repos");
            Console.WriteLine();

            while (!token.IsCancellationRequested)
            {
                const string remove = "#remove ";

                Console.Write("> ");
                var line = Console.ReadLine();

                // This occurs if CTRL-C is pushed
                if (line == null)
                {
                    continue;
                }

                if (line == "#q")
                {
                    return;
                }
                else if (line == "#all")
                {
                    await ProcessGetAllCommandsAsync(token);
                }
                else if (line == "#clear")
                {
                    await ProcessClearCacheCommandAsync(token);
                }
                else if (line.StartsWith(remove, StringComparison.Ordinal))
                {
                    var path = line.Substring(remove.Length).Trim();

                    await ProcessRemoveRepoCommandAsync(path, token);
                }
                else
                {
                    var cwd = new StringCurrentWorkingDirectory(line);

                    await ProcessGetRepoCommandAsync(cwd, token);
                }
            }
        }
Ejemplo n.º 2
0
        private async Task FindRepo(StreamWriter writer, string path, CancellationToken cancellationToken)
        {
            var cwd = new StringCurrentWorkingDirectory(path);

            var repo = await _repoCache.FindRepoAsync(cwd, cancellationToken);

            if (repo == null)
            {
                _log.Warning("Did not find a repo at '{Path}'", path);

                await writer.WriteLineAsync(string.Empty);
            }
            else
            {
                using (var jsonTextWriter = new JsonTextWriter(writer))
                {
                    _serializer.Serialize(jsonTextWriter, repo);
                }

                _log.Information("Found a repo at '{Path}'", path);
            }
        }
Ejemplo n.º 3
0
        private async Task ProcessExpandGitCommandAsync(StreamWriter writer, StreamReader reader, CancellationToken cancellationToken)
        {
            var cwd = await reader.ReadLineAsync();

            var line = await reader.ReadLineAsync();

            var scwd = new StringCurrentWorkingDirectory(cwd);

            using (var scope = _lifetimeScope.BeginLifetimeScope(b => b.RegisterInstance(scwd).As <ICurrentWorkingDirectory>()))
            {
                var tabCompleter = scope.Resolve <ITabCompleter>();

                var result = await tabCompleter.CompleteAsync(line, cancellationToken);

                using (var jsonTextWriter = new JsonTextWriter(writer))
                {
                    _serializer.Serialize(jsonTextWriter, result);
                }
            }

            _log.Information("Expanded git command '{Line}'", line);
        }