Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            try
            {
                if (args.Length < 1)
                {
                    Usage();
                    return(1);
                }

                var argList = new ArgList(args);
                if (string.IsNullOrWhiteSpace(argList.Command))
                {
                    throw new PgScanException("Command is not specified.", true);
                }

                switch (argList.Command.ToLowerInvariant())
                {
                case "report":
                    Report(argList);
                    break;

                case "publish":
                    Publish(argList);
                    break;

                default:
                    throw new PgScanException($"Invalid command: {argList.Command}", true);
                }
            }
            catch (PgScanException ex)
            {
                Console.Error.WriteLine(ex.Message);

                if (ex.WriteUsage)
                {
                    Usage();
                }

                return(ex.ExitCode);
            }

            return(0);
        }
Exemplo n.º 2
0
        private static void Report(ArgList args)
        {
            if (!args.Named.TryGetValue("input", out var inputFileName))
            {
                throw new PgScanException("Missing required argument --input=<input file name>");
            }

            args.Named.TryGetValue("type", out var typeName);
            typeName = typeName ?? GetImplicitTypeName(inputFileName);
            if (string.IsNullOrWhiteSpace(typeName))
            {
                throw new PgScanException("Missing --type argument and could not infer type based on input file name.");
            }

            var scanner = DependencyScanner.GetScanner(typeName);

            scanner.SourcePath = inputFileName;
            var projects = scanner.ResolveDependencies();

            if (projects.Count > 0)
            {
                foreach (var p in projects)
                {
                    Console.WriteLine(p.Name ?? "(project)");
                    foreach (var d in p.Dependencies)
                    {
                        Console.WriteLine($"  => {d.Name} {d.Version}");
                    }

                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("No projects found.");
            }
        }
Exemplo n.º 3
0
        private static void Publish(ArgList args)
        {
            var inputFileName = args.GetRequiredNamed("input");

            args.Named.TryGetValue("type", out var typeName);
            typeName = typeName ?? GetImplicitTypeName(inputFileName);
            if (string.IsNullOrWhiteSpace(typeName))
            {
                throw new PgScanException("Missing --type argument and could not infer type based on input file name.");
            }

            var packageFeed     = args.GetRequiredNamed("package-feed");
            var progetUrl       = args.GetRequiredNamed("proget-url");
            var consumerSource  = args.GetRequiredNamed("consumer-package-source");
            var consumerVersion = args.GetRequiredNamed("consumer-package-version");

            args.Named.TryGetValue("consumer-package-name", out var consumerName);
            args.Named.TryGetValue("consumer-package-group", out var consumerGroup);
            args.Named.TryGetValue("api-key", out var apiKey);

            string consumerFeed = null;
            string consumerUrl  = null;

            if (consumerSource.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || consumerSource.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
            {
                consumerUrl = consumerSource;
            }
            else
            {
                consumerFeed = consumerSource;
            }

            var client = new ProGetClient(progetUrl);

            var scanner = DependencyScanner.GetScanner(typeName);

            scanner.SourcePath = inputFileName;
            var projects = scanner.ResolveDependencies();

            foreach (var project in projects)
            {
                foreach (var package in project.Dependencies)
                {
                    Console.WriteLine($"Publishing consumer data for {package}...");

                    client.RecordPackageDependency(
                        package,
                        packageFeed,
                        new PackageConsumer
                    {
                        Name    = consumerName ?? project.Name,
                        Version = consumerVersion,
                        Group   = consumerGroup,
                        Feed    = consumerFeed,
                        Url     = consumerUrl
                    },
                        apiKey
                        );
                }
            }

            Console.WriteLine("Dependencies published!");
        }