github.com/getgauge/gauge@v1.6.9/cmd/template.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package cmd 8 9 import ( 10 "fmt" 11 12 "github.com/getgauge/gauge/logger" 13 "github.com/getgauge/gauge/template" 14 "github.com/spf13/cobra" 15 ) 16 17 var ( 18 templateCmd = &cobra.Command{ 19 Use: "template [flags] [args]", 20 Short: "Change template configurations", 21 Long: `Change template configurations.`, 22 Example: ` gauge template custom-template https://example.org/templates/custom-template.zip`, 23 Run: func(cmd *cobra.Command, args []string) { 24 if templateList || machineReadable { 25 text, err := template.List(machineReadable) 26 if err != nil { 27 logger.Fatal(true, err.Error()) 28 } 29 fmt.Println(text) 30 return 31 } 32 if len(args) == 0 { 33 exit(fmt.Errorf("template command needs argument(s)"), cmd.UsageString()) 34 } 35 if len(args) == 1 { 36 text, err := template.Get(args[0]) 37 if err != nil { 38 logger.Fatal(true, err.Error()) 39 } 40 logger.Info(true, text) 41 return 42 } 43 err := template.Update(args[0], args[1]) 44 if err != nil { 45 logger.Fatal(true, err.Error()) 46 } 47 }, 48 DisableAutoGenTag: true, 49 } 50 templateList bool 51 ) 52 53 func init() { 54 GaugeCmd.AddCommand(templateCmd) 55 templateCmd.Flags().BoolVarP(&templateList, "list", "", false, "List all template properties") 56 }