gitee.com/mirrors/gauge@v1.0.6/cmd/man.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 // +build linux darwin 19 20 package cmd 21 22 import ( 23 "strings" 24 25 "os" 26 27 "path/filepath" 28 29 "github.com/getgauge/common" 30 "github.com/getgauge/gauge/logger" 31 "github.com/getgauge/gauge/version" 32 "github.com/spf13/cobra" 33 "github.com/spf13/cobra/doc" 34 ) 35 36 const manDir = "man" 37 38 var ( 39 manCmd = &cobra.Command{ 40 Use: "man [flags]", 41 Short: "Generate man pages", 42 Long: `Generate man pages.`, 43 Example: ` gauge man`, 44 Run: func(cmd *cobra.Command, args []string) { 45 out, err := getDefaultPath() 46 if err != nil { 47 logger.Fatalf(true, "Cannot find the gauge home directory.") 48 } 49 if err := genManPages(out); err != nil { 50 logger.Fatalf(true, err.Error()) 51 } 52 }, 53 DisableAutoGenTag: true, 54 } 55 ) 56 57 func init() { 58 GaugeCmd.AddCommand(manCmd) 59 } 60 61 func getDefaultPath() (string, error) { 62 p, err := common.GetGaugeHomeDirectory() 63 if err != nil { 64 return "", err 65 } 66 return filepath.Join(p, manDir, "man1"), nil 67 } 68 69 func genManPages(out string) error { 70 if err := os.MkdirAll(out, common.NewDirectoryPermissions); err != nil { 71 return err 72 } 73 if err := doc.GenManTreeFromOpts(setupCmd(), doc.GenManTreeOptions{ 74 Header: &doc.GenManHeader{ 75 Title: "GAUGE", 76 Section: "1", 77 Manual: "GAUGE MANUAL", 78 Source: "GAUGE " + version.CurrentGaugeVersion.String(), 79 }, 80 Path: out, 81 CommandSeparator: "-", 82 }); err != nil { 83 return err 84 } 85 p := strings.TrimSuffix(out, filepath.Base(out)) 86 logger.Infof(true, "To view gauge man pages, add `%s` to `MANPATH` environment variable.", p) 87 return nil 88 } 89 90 func setupCmd() *cobra.Command { 91 GaugeCmd.Short = "A light-weight cross-platform test automation tool" 92 GaugeCmd.Long = "Gauge is a light-weight cross-platform test automation tool with the ability to author test cases in the business language." 93 return GaugeCmd 94 }