Beispiel #1
0
        protected override int Execute()
        {
            var baseResult = base.Execute();

            if (baseResult != 0)
            {
                return(baseResult);
            }

            var metadata = new GenymanMetadata();
            var version  = GetVersion();

            Log.Information($"Executing new command for {metadata.PackageId} - Version {version}");

            var sw = Stopwatch.StartNew();

            var configuration = new GenymanConfiguration <TConfiguration>
            {
                Genyman       = metadata,
                Configuration = new TTemplate(),
            };

            var output    = "";
            var extension = "json";

            if (JsonOption.HasValue())
            {
                output    = configuration.ToJsonString();
                extension = "json";
            }
            else             //Later support more formats!
            {
                // DEFAULT is json
                output    = configuration.ToJsonString();
                extension = "json";
            }

            var fileName = !string.IsNullOrEmpty(FileNameOption.Value()) ? FileNameOption.ParsedValue : $"gm-{metadata.Identifier.ToLower()}";

            fileName = $"{fileName}.{extension}";

            var fullFileName = Path.Combine(Environment.CurrentDirectory, fileName);

            if (File.Exists(fileName) && !Overwrite.HasValue())
            {
                Log.Error($"File {fullFileName} already exists. Specify --overwrite if you want to overwrite files");
                return(-1);
            }

            File.WriteAllText(fullFileName, output);
            Log.Information($"Configuration file {fileName} was written");

            Log.Information($"Finished ({sw.ElapsedMilliseconds}ms)");

            return(0);
        }
Beispiel #2
0
        protected override int Execute()
        {
            base.Execute();

            var metaData = new GenymanMetadata();
            var version  = GetVersion();

            if (Input.Value.IsNullOrEmpty())
            {
                Description = $"{metaData.Description} (Version {version})";
                Name        = metaData.Identifier.ToLower();
                ShowHelp();
                return(-1);
            }

            var fileName = Input.ParsedValue;

            if (!File.Exists(fileName))
            {
                Log.Error($"Could not find input file {fileName}");
                return(-1);
            }

            var configurationContents = File.ReadAllText(fileName);
            GenymanConfiguration <TConfiguration> genyManConfiguration;

            try
            {
                //todo: based upon extension parse this
                genyManConfiguration = configurationContents.FromJsonString <TConfiguration>();
            }
            catch (Exception e)
            {
                Log.Debug(e.Message);
                Log.Error($"Could not parse {fileName} as a valid Genyman input file");
                return(-1);
            }

            var generator = new TGenerator
            {
                InputFileName         = fileName,
                ConfigurationMetadata = genyManConfiguration.Genyman,
                Configuration         = genyManConfiguration.Configuration,
                WorkingDirectory      = new FileInfo(fileName).DirectoryName,
                Metadata  = metaData,
                Overwrite = Overwrite.HasValue(),
                Update    = UpdateOption?.HasValue() ?? false
            };

            var sw = Stopwatch.StartNew();

            Log.Information($"Executing {generator.Metadata.PackageId} - Version {version}");
            generator.Execute();
            var elapsed = sw.ElapsedMilliseconds;

            Log.Information($"Finished {generator.Metadata.PackageId} ({elapsed}ms)");

            // telemetry
            if (metaData.PackageId.ToLower() != "genyman")
            {
                const string telemetryUrl = "https://cmgg8m1ib1.execute-api.us-east-2.amazonaws.com/genyman";
                telemetryUrl.PostJsonToUrl(new Telemetry()
                {
                    Name = metaData.PackageId, Version = metaData.Version, Duration = elapsed
                });
            }

            return(0);
        }