gitee.com/mirrors/gauge@v1.0.6/cmd/refactor.go (about) 1 // Copyright 2015 ThoughtWorks, Inc. 2 3 // This file is part of Gauge. 4 5 // Gauge is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 10 // Gauge is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with Gauge. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "fmt" 22 23 "github.com/getgauge/gauge/api" 24 "github.com/getgauge/gauge/config" 25 "github.com/getgauge/gauge/refactor" 26 "github.com/spf13/cobra" 27 ) 28 29 var refactorCmd = &cobra.Command{ 30 Use: "refactor [flags] <old step> <new step> [args]", 31 Short: "Refactor steps", 32 Long: `Refactor steps.`, 33 Example: ` gauge refactor "old step" "new step"`, 34 Run: func(cmd *cobra.Command, args []string) { 35 loadEnvAndReinitLogger(cmd) 36 if len(args) < 2 { 37 exit(fmt.Errorf("Refactor command needs at least two arguments."), cmd.UsageString()) 38 } 39 if err := config.SetProjectRoot(args); err != nil { 40 exit(err, cmd.UsageString()) 41 } 42 refactorInit(args) 43 }, 44 DisableAutoGenTag: true, 45 } 46 47 func init() { 48 GaugeCmd.AddCommand(refactorCmd) 49 } 50 51 func refactorInit(args []string) { 52 startChan := api.StartAPI(false) 53 refactor.RefactorSteps(args[0], args[1], startChan, getSpecsDir(args[2:])) 54 }