github.com/projectriff/riff-cli@v0.0.5-0.20180301104501-5db7a3bd9fc1/cmd/docs_generator.go (about) 1 /* 2 * Copyright 2018 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "github.com/spf13/cobra" 21 "github.com/projectriff/riff-cli/pkg/osutils" 22 "github.com/spf13/cobra/doc" 23 "github.com/projectriff/riff-cli/pkg/ioutils" 24 "os" 25 ) 26 27 var directory string 28 var createDir bool 29 30 var docsCmd = &cobra.Command{ 31 Use: "docs", 32 Short: "generate riff-cli command documentation", 33 Long: `Generate riff-cli command documentation`, 34 Hidden: true, 35 Run: func(cmd *cobra.Command, args []string) { 36 37 if !osutils.IsDirectory(directory) { 38 os.Mkdir(directory,0744) 39 } 40 41 err := doc.GenMarkdownTree(rootCmd, directory) 42 if err != nil { 43 ioutils.Errorf("Doc generation failed %v\n", err) 44 os.Exit(1) 45 } 46 }, 47 } 48 49 50 func init() { 51 rootCmd.AddCommand(docsCmd) 52 docsCmd.Flags().StringVarP(&directory, "dir", "d", osutils.Path(osutils.GetCWD()+"/docs"),"the output directory for the docs.") 53 54 }