Example #1
0
        public async Task ExecuteLiterals(
            [Option("-i", "comma separated key=value style literals. (ex. foo=bar,hoge=fuga")] string inputs,
            [Option("-o", "path to the output kustomization file.")] string outputPath,
            [Option("-n", "configmap name of ConfigMapGenerator.")] string name,
            [Option("-b", "ConfigMapGenerator behavior.")] Behavior behavior       = Behavior.unspecified,
            [Option("-skip", "skip configMapGenerator: output.")] bool skipHeader  = false,
            [Option("-a", "append just an value to existing config.")] bool append = false,
            [Option("-f", "override outputfile without prompt.")] bool forceOutput = false,
            [Option("-d", "dry run.")] bool dryRun = true
            )
        {
            var generator = new LiteralConfigMapGenerator(name, behavior, skipHeader);
            var keyvalues = inputs.Split(',');
            var contents  = generator.Generate(keyvalues);

            if (dryRun)
            {
                Context.Logger.LogInformation("dryrun mode detected. see output contents.");
                Context.Logger.LogInformation("");
                Context.Logger.LogInformation(contents);
            }
            else
            {
                Context.Logger.LogInformation($"begin writing following contents to {outputPath}.");
                Context.Logger.LogInformation("");
                Context.Logger.LogInformation(contents);

                await generator.WriteAsync(contents, outputPath, forceOutput, append, Context.CancellationToken);
            }
        }
Example #2
0
        public void UnspecifiedAppendContentsTest(string name, Behavior behavior, bool skipHeader)
        {
            var generator = new LiteralConfigMapGenerator(name, behavior, skipHeader);
            var actual    = generator.Generate(inputs);
            // result is always LF
            var expected = @$ "  - name: {name}
    literals:
      - foo=bar
      - piyo=poyo
      - hoge=fuga
".Replace("\r\n", "\n");

            Assert.NotNull(actual);
            Assert.Equal(expected, actual);
        }