Exemplo n.º 1
0
        public bool HasValidArguments(string[] args)
        {
            (var ok, OpenCommandArgs openCommandArgs) = OpenCommandArgs.Parse(args);

            if (ok)
            {
                _parsedArgs = openCommandArgs;
            }

            return(ok);
        }
Exemplo n.º 2
0
        public static (bool ok, OpenCommandArgs parsedArgs) Parse(string[] args)
        {
            var openCommandArgs = new OpenCommandArgs();

            (var foundAlias, Alias alias) = TryResolveKnownAlias(args);

            var directory = foundAlias
                ? alias.DirectoryPath
                : ResolveGitRepositoryRootDirectory(args);

            var gitRepositoryUrl = ResolveGitRepositoryUrl(directory);

            var urlParams = new List <IParam>
            {
                new IssuesParam(),
                new PullRequestParam()
            };

            openCommandArgs.GitHubUrl = gitRepositoryUrl;

            foreach (var param in urlParams)
            {
                (var ok, var parsedParam) = foundAlias ? param.Parse(alias.Parameters) : param.Parse(args);

                if (ok)
                {
                    openCommandArgs.GitHubUrl = $"{gitRepositoryUrl}/{parsedParam.UrlFragment}";
                }
            }

            if (string.IsNullOrEmpty(openCommandArgs.GitHubUrl))
            {
                return(false, null);
            }

            return(true, openCommandArgs);
        }