2017-06-26 23:46:34 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
2017-04-12 20:04:04 +02:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-23 01:56:15 +02:00
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2017-04-12 20:04:04 +02:00
|
|
|
"github.com/golang/glog"
|
|
|
|
"github.com/spf13/cobra"
|
2017-04-13 14:27:45 +02:00
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
"github.com/pulumi/pulumi-fabric/pkg/diag/colors"
|
2017-08-02 18:25:22 +02:00
|
|
|
"github.com/pulumi/pulumi-fabric/pkg/util/cmdutil"
|
2017-04-12 20:04:04 +02:00
|
|
|
)
|
|
|
|
|
2017-06-07 19:52:03 +02:00
|
|
|
// NewLumiCmd creates a new Lumi Cmd instance.
|
2017-05-18 20:38:28 +02:00
|
|
|
func NewLumiCmd() *cobra.Command {
|
2017-05-31 18:14:49 +02:00
|
|
|
var logFlow bool
|
2017-04-12 20:04:04 +02:00
|
|
|
var logToStderr bool
|
|
|
|
var verbose int
|
|
|
|
cmd := &cobra.Command{
|
2017-05-18 20:38:28 +02:00
|
|
|
Use: "lumi",
|
|
|
|
Short: "Lumi is a framework and toolset for reusable stacks of services",
|
2017-04-12 20:04:04 +02:00
|
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
2017-05-31 18:14:49 +02:00
|
|
|
cmdutil.InitLogging(logToStderr, verbose, logFlow)
|
2017-04-12 20:04:04 +02:00
|
|
|
},
|
|
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
glog.Flush()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-31 18:14:49 +02:00
|
|
|
cmd.PersistentFlags().BoolVar(&logFlow, "logflow", false, "Flow log settings to child processes (like plugins)")
|
2017-04-12 20:04:04 +02:00
|
|
|
cmd.PersistentFlags().BoolVar(&logToStderr, "logtostderr", false, "Log to stderr instead of to files")
|
|
|
|
cmd.PersistentFlags().IntVarP(
|
|
|
|
&verbose, "verbose", "v", 0, "Enable verbose logging (e.g., v=3); anything >3 is very verbose")
|
|
|
|
|
|
|
|
cmd.AddCommand(newConfigCmd())
|
|
|
|
cmd.AddCommand(newDeployCmd())
|
|
|
|
cmd.AddCommand(newDestroyCmd())
|
|
|
|
cmd.AddCommand(newEnvCmd())
|
|
|
|
cmd.AddCommand(newPlanCmd())
|
|
|
|
cmd.AddCommand(newVersionCmd())
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
2017-06-02 21:43:04 +02:00
|
|
|
|
2017-08-22 19:07:25 +02:00
|
|
|
func pkgargFromArgs(args []string) string {
|
|
|
|
if len(args) > 0 {
|
|
|
|
return args[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
func confirmPrompt(msg string, name string) bool {
|
|
|
|
prompt := fmt.Sprintf(msg, name)
|
|
|
|
fmt.Print(
|
|
|
|
colors.ColorizeText(fmt.Sprintf("%v%v%v\n", colors.SpecAttention, prompt, colors.Reset)))
|
|
|
|
fmt.Printf("Please confirm that this is what you'd like to do by typing (\"%v\"): ", name)
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
if line, _ := reader.ReadString('\n'); line != name+"\n" {
|
|
|
|
fmt.Fprintf(os.Stderr, "Confirmation declined -- exiting without doing anything\n")
|
|
|
|
return false
|
2017-06-02 21:43:04 +02:00
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
return true
|
2017-06-02 21:43:04 +02:00
|
|
|
}
|