Skip to content

Commit

Permalink
[fix] output directory calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
elek committed Aug 15, 2020
1 parent fd26358 commit d15090a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
27 changes: 15 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {
},
},
Action: func(c *cli.Context) error {
outputDir := findOutputDir(&outputDir)
outputDir := findOutputDir(&outputDir, c.Args().Get(0))
if c.Bool("print") {
outputDir = "-"
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func main() {
Usage: "List managed kubernetes resources files.",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(&inputDir, c.Args().Get(0)), findOutputDir(&outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(&inputDir, c.Args().Get(0)), findOutputDir(&outputDir, c.Args().Get(0)))
pkg.ListResources(context)
return nil
},
Expand All @@ -136,7 +136,7 @@ func main() {
},
},
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(&inputDir, c.Args().Get(0)), findOutputDir(&outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(&inputDir, c.Args().Get(0)), findOutputDir(&outputDir, c.Args().Get(0)))
err := context.Init()
if err != nil {
return err
Expand All @@ -159,7 +159,7 @@ func main() {
},
},
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(&inputDir, c.Args().Get(0)), findOutputDir(&outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(&inputDir, c.Args().Get(0)), findOutputDir(&outputDir, c.Args().Get(0)))
return pkg.Cleanup(context, c.Bool("all"))
},
},
Expand Down Expand Up @@ -194,7 +194,7 @@ func appCommands(inputDir *string, outputDir *string) cli.Command {
Usage: "List all the referenced/imported flekszible directory.",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir, c.Args().Get(0)))
pkg.ListApp(context)
return nil
},
Expand All @@ -204,7 +204,7 @@ func appCommands(inputDir *string, outputDir *string) cli.Command {
Usage: "Search for available importable apps/dirs from the active sources",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir, c.Args().Get(0)))
pkg.SearchComponent(context)
return nil
},
Expand All @@ -214,7 +214,7 @@ func appCommands(inputDir *string, outputDir *string) cli.Command {
Usage: "Add (import) new app to the flekszible.yaml.",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir, c.Args().Get(0)))
pkg.AddApp(context, *inputDir, c.Args().First())
return nil
},
Expand All @@ -233,7 +233,7 @@ func sourceCommands(inputDir, outputDir *string) cli.Command {
Usage: "List registered sources (directories / repositories where other directories are imported from)",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir, c.Args().Get(0)))
pkg.ListSources(context)
return nil
},
Expand All @@ -251,7 +251,7 @@ func sourceCommands(inputDir, outputDir *string) cli.Command {
Usage: "Register source to your Flekszible descriptor file",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir, c.Args().Get(0)))
return pkg.AddSource(context, findInputDir(inputDir, c.Args().Get(0)), c.Args().First())
},
},
Expand All @@ -271,7 +271,7 @@ func transformationCommands(inputDir, outputDir *string) cli.Command {
Usage: "List available transformation types.",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, c.Args().Get(0)), findOutputDir(outputDir, c.Args().Get(0)))
return pkg.ListProcessor(context)
},
},
Expand All @@ -281,7 +281,7 @@ func transformationCommands(inputDir, outputDir *string) cli.Command {
Usage: "Show details information / help about a specific transformation type",
ArgsUsage: "[flekszible_dir]",
Action: func(c *cli.Context) error {
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, ""), findOutputDir(outputDir))
context := processor.CreateRenderContext("k8s", findInputDir(inputDir, ""), findOutputDir(outputDir, c.Args().Get(0)))
return pkg.ShowProcessor(context, c.Args().First())
},
},
Expand Down Expand Up @@ -316,7 +316,10 @@ func findInputDir(argument *string, inputDirFromArg string) string {
return pwd
}

func findOutputDir(argument *string) string {
func findOutputDir(argument *string, outputDirFromArg string) string {
if len(outputDirFromArg) > 0 {
return outputDirFromArg
}
if *argument != "" {
return *argument
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func PrintTree(node *processor.ResourceNode, prefix string) {
if len(node.Resources) > 0 {
fmt.Println(prefix + " RESOURCES:")
for _, resource := range node.Resources {
fmt.Println(prefix + " " + resource.Name() + "/" + resource.Kind())
resourceLine := prefix + " " + resource.Name() + "/" + resource.Kind()
if len(resource.Destination) > 0 {
resourceLine += " ( --> " + resource.Destination + ")"
}
fmt.Println(resourceLine)
}
}
if len(node.ProcessorRepository.Processors) > 0 {
Expand Down

0 comments on commit d15090a

Please sign in to comment.