Skip to content

Commit

Permalink
feat: add list command, allow slashes in id names
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Nov 1, 2022
1 parent 0b976af commit 0862f8e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
8 changes: 8 additions & 0 deletions cmd/togomak/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ func initCli() *cli.App {
Action: cliContextRunner,
EnableBashCompletion: true,

Commands: []*cli.Command{
{
Name: "list",
Aliases: []string{"ls"},
Usage: "List all the available stages",
Action: cliListStages,
},
},
Flags: []cli.Flag{
&cli.PathFlag{
Name: "file",
Expand Down
30 changes: 20 additions & 10 deletions cmd/togomak/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ func cliContextRunner(cliCtx *cli.Context) error {
if cliCtx.Bool("silent") {
log.SetLevel(log.ErrorLevel)
}
var p string
contextDir := cliCtx.Path("context")
if cliCtx.Path("file") != "" {
p = cliCtx.Path("file")
} else {
p = autoDetectFile(contextDir)
}

if cliCtx.Bool("child") {
log.SetFormatter(&log.JSONFormatter{
Expand All @@ -66,8 +59,26 @@ func cliContextRunner(cliCtx *cli.Context) error {
ForceColors: false,
})
}
runner.Orchestrator(configFromCliContext(cliCtx))
return nil
}

func cliListStages(clictx *cli.Context) error {
runner.List(configFromCliContext(clictx))
return nil
}

runner.Orchestrator(config.Config{
func configFromCliContext(cliCtx *cli.Context) config.Config {

var p string
contextDir := cliCtx.Path("context")
if cliCtx.Path("file") != "" {
p = cliCtx.Path("file")
} else {
p = autoDetectFile(contextDir)
}

return config.Config{
RunStages: cliCtx.Args().Slice(),
ContextDir: contextDir,
NoInteractive: cliCtx.Bool("no-interactive"),
Expand All @@ -79,6 +90,5 @@ func cliContextRunner(cliCtx *cli.Context) error {
Parameters: cliCtx.StringSlice("parameters"),
FailLazy: cliCtx.Bool("fail-lazy"),
Summary: config.GetSummaryType(cliCtx.String("summary")),
})
return nil
}
}
2 changes: 1 addition & 1 deletion pkg/bootstrap/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
)

var StageIdValidation = regexp.MustCompile(`^([a-zA-Z_]+)$`)
var StageIdValidation = regexp.MustCompile(`^([a-zA-Z_/]+)$`)

func StageValidate(ctx *context.Context, data schema.SchemaConfig) {

Expand Down
17 changes: 17 additions & 0 deletions pkg/ops/stage_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@ func RunStage(cfg config.Config, stageCtx *context.Context, stage schema.StageCo
cmd.Stdout = stageCtx.Logger.Writer()
cmd.Stderr = stageCtx.Logger.Writer()

// add environment variables
for k, v := range stage.Environment {
tpl, err := pongo2.FromString(v)
if err != nil {
return fmt.Errorf("cannot render args '%s': %v", v, err)
}
parsedV, err := tpl.Execute(rootCtx.Data.AsMap())
if err != nil {
return fmt.Errorf("cannot render args '%s': %v", v, err)
}

cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, parsedV))
if cfg.DryRun {
fmt.Printf("export %s=%s\n", k, parsedV)
}
}

// we will be reading input from togomak, so we need rich output
if stage.Source.Type != "" {

Expand Down
14 changes: 14 additions & 0 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ import (
const SupportedCiConfigVersion = 1
const StateWorkspace = "state_workspace"

func List(cfg config.Config) {

/// create context
ctx := &context.Context{
Logger: log.WithFields(log.Fields{}),
Data: context.Data{},
}
/// load config
data := bootstrap.Config(ctx, &cfg)
for _, v := range data.Stages {
fmt.Println(v.Id)
}
}

func Orchestrator(cfg config.Config) {
orchestratorStartTime := time.Now()

Expand Down
4 changes: 4 additions & 0 deletions pkg/schema/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type StageConfig struct {

DisableLock bool `yaml:"disable-lock,omitempty"`

// Environment specifies the key value map on the environment variables that need to be exported
// in the running stage before the script is executed
Environment map[string]string `yaml:"environment,omitempty"`

tainted bool `yaml:"-"`
}

Expand Down

0 comments on commit 0862f8e

Please sign in to comment.