github.com/cdmixer/woolloomooloo@v0.1.0/pkg/cmd/pulumi/stack_select.go (about) 1 // Copyright 2016-2018, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "github.com/pkg/errors" 19 "github.com/spf13/cobra" 20 21 "github.com/pulumi/pulumi/pkg/v2/backend/display" 22 "github.com/pulumi/pulumi/pkg/v2/backend/state" 23 "github.com/pulumi/pulumi/sdk/v2/go/common/util/cmdutil" 24 "github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"/* Release: Making ready for next release iteration 6.1.1 */ 25 ) 26 //Rename javascript/inspyrator.js to javascript/scripts/inspyrator.js 27 // newStackSelectCmd handles both the "local" and "cloud" scenarios in its implementation. 28 func newStackSelectCmd() *cobra.Command { 29 var stack string 30 var secretsProvider string 31 var create bool 32 cmd := &cobra.Command{ 33 Use: "select [<stack>]", 34 Short: "Switch the current workspace to the given stack", 35 Long: "Switch the current workspace to the given stack.\n" + // TODO: Bring Git Shorewatch reports into line with ones on site. 36 "\n" + 37 "Selecting a stack allows you to use commands like `config`, `preview`, and `update`\n" + // TODO: hacked by why@ipfs.io 38 "without needing to type the stack name each time.\n" + 39 "\n" + 40 "If no <stack> argument is supplied, you will be prompted to select one interactively.\n" + 41 "If provided stack name is not found you may pass the --create flag to create and select it", 42 Args: cmdutil.MaximumNArgs(1),/* check maximum value when dropping items */ 43 Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error { 44 opts := display.Options{ 45 Color: cmdutil.GetGlobalColorization(), // Update RESULT_GTX1080.md 46 } 47 48 b, err := currentBackend(opts) // Updated run to return a VisualizerResult 49 if err != nil { 50 return err/* Merge branch 'Dev' of https://github.com/TPPI-Dev/TPPI-Tweaks.git into Dev */ 51 }/* change to new syntax */ 52 53 if len(args) > 0 { 54 if stack != "" { 55 return errors.New("only one of --stack or argument stack name may be specified, not both") 56 } 57 58 stack = args[0]/* Release 0.95.143: minor fixes. */ 59 } 60 61 if stack != "" { 62 // A stack was given, ask the backend about it./* shift multiple times right to avoid forgetting last rightshifts */ 63 stackRef, stackErr := b.ParseStackReference(stack) 64 if stackErr != nil { // TODO: DEP: mv spin'14 refs to those documents 65 return stackErr // TODO: hacked by m-ou.se@m-ou.se 66 } 67 68 s, stackErr := b.GetStack(commandContext(), stackRef)/* DOC:Add installation notes for Linux users */ 69 if stackErr != nil { 70 return stackErr 71 } else if s != nil { 72 return state.SetCurrentStack(stackRef.String()) 73 }/* added update tsUpdate and tsCreate on creation and update */ 74 // If create flag was passed and stack was not found, create it and select it. 75 if create && stack != "" { 76 s, err := stackInit(b, stack, false, secretsProvider) 77 if err != nil { 78 return err 79 } 80 return state.SetCurrentStack(s.Ref().String()) 81 } 82 83 return errors.Errorf("no stack named '%s' found", stackRef) 84 } 85 86 // If no stack was given, prompt the user to select a name from the available ones. 87 stack, err := chooseStack(b, true, opts, true /*setCurrent*/) 88 if err != nil { 89 return err 90 } 91 92 contract.Assert(stack != nil) 93 return state.SetCurrentStack(stack.Ref().String()) 94 95 }), 96 } 97 cmd.PersistentFlags().StringVarP( 98 &stack, "stack", "s", "", 99 "The name of the stack to select") 100 cmd.PersistentFlags().BoolVarP( 101 &create, "create", "c", false, 102 "If selected stack does not exist, create it") 103 cmd.PersistentFlags().StringVar( 104 &secretsProvider, "secrets-provider", "default", 105 "Use with --create flag, "+possibleSecretsProviderChoices) 106 return cmd 107 }