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

Update the plan command. #387

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (c *DeployCommand) Run(args []string) int {
}

if !config.Deploy.Force {
p := levant.PlanConfig{
p := structs.LevantPlanConfig{
Client: config.Client,
Plan: config.Plan,
Template: config.Template,
Expand Down
31 changes: 25 additions & 6 deletions command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/levant/levant"
"github.com/hashicorp/levant/levant/structs"
"github.com/hashicorp/levant/logging"
"github.com/hashicorp/levant/output"
"github.com/hashicorp/levant/template"
)

Expand Down Expand Up @@ -48,7 +49,15 @@ General Options:

-force-count
Use the taskgroup count from the Nomad jobfile instead of the count that
is currently set in a running job.
is currently set in a running job.

-output-format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-output-format is perhaps redundant? maybe just -format?

update: i see that this is drawing a distinction against -log-format... 🤔

Specify the format of plan to be emitted. Valid values include JSON, DIFF,
and NDJSON. The default is DIFF.

-output-to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render has a similar config, but it uses the -out:

-out=<file>

Specify the destination for the diff. Valid values include CLI, LOG, STDOUT,
and STDERR. The default is LOG.

-ignore-no-changes
By default if no changes are detected when running a plan Levant will
Expand Down Expand Up @@ -81,11 +90,14 @@ func (c *PlanCommand) Synopsis() string {
func (c *PlanCommand) Run(args []string) int {

var err error
var level, format string
config := &levant.PlanConfig{
var logLevel, logFormat, outFormat, outDest string
config := &structs.LevantPlanConfig{
Client: &structs.ClientConfig{},
Plan: &structs.PlanConfig{},
Template: &structs.TemplateConfig{},
Output: &structs.DiffOutputConfig{
UI: &c.UI,
},
}

flags := c.Meta.FlagSet("plan", FlagSetVars)
Expand All @@ -95,8 +107,10 @@ func (c *PlanCommand) Run(args []string) int {
flags.BoolVar(&config.Client.AllowStale, "allow-stale", false, "")
flags.StringVar(&config.Client.ConsulAddr, "consul-address", "", "")
flags.BoolVar(&config.Plan.IgnoreNoChanges, "ignore-no-changes", false, "")
flags.StringVar(&level, "log-level", "INFO", "")
flags.StringVar(&format, "log-format", "HUMAN", "")
flags.StringVar(&logLevel, "log-level", "INFO", "")
flags.StringVar(&logFormat, "log-format", "HUMAN", "")
flags.StringVar(&outFormat, "output-format", "DIFF", "")
flags.StringVar(&outDest, "output-to", "LOG", "")
flags.Var((*helper.FlagStringSlice)(&config.Template.VariableFiles), "var-file", "")

if err = flags.Parse(args); err != nil {
Expand All @@ -105,7 +119,12 @@ func (c *PlanCommand) Run(args []string) int {

args = flags.Args()

if err = logging.SetupLogger(level, format); err != nil {
if err = logging.SetupLogger(logLevel, logFormat); err != nil {
c.UI.Error(err.Error())
return 1
}

if err = output.ConfigureOutputSettings(config, &outFormat, &outDest); err != nil {
c.UI.Error(err.Error())
return 1
}
Expand Down
Loading