Ejemplo n.º 1
0
        public async Task ExecuteFile(
            [Option("-i", "path to the base directory to search.")] string inputPath,
            [Option("-o", "path to the output kustomization file.")] string outputPath,
            [Option("-s", "search pattern of files. (ex. *.config)")] string searchPattern,
            [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 FileConfigMapGenerator(name, behavior, skipHeader);
            var contents  = generator.Generate(inputPath, searchPattern);

            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);
            }
        }
Ejemplo n.º 2
0
        public void UnspecifiedAppendContentsTest(string name, Behavior behavior, bool skipHeader)
        {
            var generator = new FileConfigMapGenerator(name, behavior, skipHeader);
            var actual    = generator.Generate(basePath, "*.json");
            // result is always LF
            var expected = @$ "  - name: {name}
    files:
      - /bar.json
      - /foo.json
      - /hoge.json
".Replace("\r\n", "\n");

            Assert.NotNull(actual);
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public void PathNotExistsTest(string name, Behavior behavior, bool skipHeader)
        {
            var generator = new FileConfigMapGenerator(name, behavior, skipHeader);

            Assert.Throws <DirectoryNotFoundException>(() => generator.Generate("FooBar", "*.json"));
        }