Skip to content

Commit 6c73563

Browse files
FEATURE: add printer
add printer for dockerfile, config, and env allows easy export to a dockerfile workspace
1 parent 8350bb2 commit 6c73563

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Cli struct {
1919
TemplatesDir string `default:"." help:"Home project directory containing a templates/ directory which in turn contains pups yaml templates." predictor:"dir"`
2020
DockerCompose DockerComposeCmd `cmd:"" name:"compose" help:"Create docker compose setup in the output {output-directory}/{config}/. The builder generates a docker-compose.yaml, Dockerfile, config.yaml, and an env file for you to source .envrc. Run with 'source .envrc; docker compose up'."`
2121
ConcourseJob ConcourseJobCmd `cmd:"" name:"concourse-job" help:"Print concourse job config"`
22+
Print PrintCmd `cmd:"" name:"print" help:"Print config"`
2223

2324
InstallCompletions kongplete.InstallCompletions `cmd:"" aliases:"sh" help:"Print shell autocompletions. Add output to dotfiles, or 'source <(./launcher-extras sh)'."`
2425
}

printer.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"slices"
7+
8+
"github.com/discourse/launcher/v2/config"
9+
"github.com/discourse/launcher/v2/utils"
10+
11+
"gopkg.in/yaml.v3"
12+
)
13+
14+
type PrintCmd struct {
15+
Type string `arg:"" enum:"dockerfile,config,env" help:"print parts of a config"`
16+
Config string `arg:"" name:"config" help:"config" predictor:"config"`
17+
}
18+
19+
func (r *PrintCmd) Run(cli *Cli) error {
20+
loadedConfig, err := config.LoadConfig(cli.ConfDir, r.Config, true, cli.TemplatesDir)
21+
if err != nil {
22+
return err
23+
}
24+
switch r.Type {
25+
case "dockerfile":
26+
pupsArgs := "--skip-tags=precompile,migrate,db"
27+
fmt.Println(loadedConfig.Dockerfile(pupsArgs, "config.yaml"))
28+
case "env":
29+
env := map[string]string{}
30+
for k, v := range loadedConfig.Env {
31+
if slices.Contains(utils.KnownSecrets, k) {
32+
continue
33+
}
34+
env[k] = v
35+
}
36+
var b bytes.Buffer
37+
encoder := yaml.NewEncoder(&b)
38+
encoder.SetIndent(2)
39+
if err := encoder.Encode(&env); err != nil {
40+
return err
41+
}
42+
yaml := b.Bytes()
43+
fmt.Println(string(yaml))
44+
default:
45+
fmt.Println(loadedConfig.Yaml())
46+
}
47+
return nil
48+
}

0 commit comments

Comments
 (0)