Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add -parse-only option #1545

Merged
merged 4 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ func (cli *CLI) ParseFlags(args []string) (
return nil
}), "once", "")

flags.Var((funcBoolVar)(func(b bool) error {
c.ParseOnly = *(config.Bool(b))
return nil
}), "parse-only", "")

flags.Var((funcVar)(func(s string) error {
c.PidFile = config.String(s)
return nil
Expand Down Expand Up @@ -776,6 +781,9 @@ Options:
-once
Do not run the process as a daemon. This disables wait/quiescence timers.

-parse-only
Do not process templates. Parse them for structure.

-pid-file=<path>
Path on disk to write the PID of the process

Expand Down
8 changes: 8 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,14 @@ func TestCLI_ParseFlags(t *testing.T) {
},
false,
},
{
"parse-only",
[]string{"-parse-only"},
&config.Config{
ParseOnly: true,
},
false,
},
}

for i, tc := range cases {
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ type Config struct {
// Run once, executing each template exactly once, and exit
Once bool

// ParseOnly prevents any rendering and only loads the templates for
// checking well formedness.
ParseOnly bool

// BlockQueryWaitTime is amount of time in seconds to do a blocking query for
BlockQueryWaitTime *time.Duration `mapstructure:"block_query_wait"`
}
Expand Down Expand Up @@ -163,6 +167,7 @@ func (c *Config) Copy() *Config {
}

o.Once = c.Once
o.ParseOnly = c.ParseOnly

o.BlockQueryWaitTime = c.BlockQueryWaitTime

Expand Down Expand Up @@ -250,6 +255,7 @@ func (c *Config) Merge(o *Config) *Config {
}

r.Once = o.Once
r.ParseOnly = o.ParseOnly

return r
}
Expand Down
12 changes: 12 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,18 @@ func TestConfig_Merge(t *testing.T) {
},
},
},
{
"parse-only",
&Config{
ParseOnly: false,
},
&Config{
ParseOnly: true,
},
&Config{
ParseOnly: true,
},
},
}

for i, tc := range cases {
Expand Down
20 changes: 20 additions & 0 deletions manager/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ func (r *Runner) Start() {
r.ErrCh <- err
return
}
if r.config.ParseOnly {
log.Printf("[INFO] (runner) ParseOnly mode and all templates parsed")

if r.child != nil {
r.stopDedup()
r.stopWatcher()

log.Printf("[INFO] (runner) waiting for child process to exit")
select {
case c := <-childExitCh:
log.Printf("[INFO] (runner) child process died")
r.ErrCh <- NewErrChildDied(c)
return
case <-r.DoneCh:
}
}

r.Stop()
return
}

for {
// Warn the user if they are watching too many dependencies.
Expand Down