Add script to generate CLI Structure

This commit adds a script to generate the CLI structure.
Also, adds the structure to README.md
This commit is contained in:
Shubham Minglani
2018-02-05 11:49:23 +05:30
parent db9d2754dd
commit c5e9da8a86
4 changed files with 85 additions and 1 deletions

View File

@@ -45,4 +45,8 @@ test-coverage:
# compile for multiple platforms
.PHONY: cross
cross:
gox -osarch="darwin/amd64 linux/amd64 linux/arm windows/amd64" -output="bin/{{.OS}}-{{.Arch}}/ocdev" $(BUILD_FLAGS)
gox -osarch="darwin/amd64 linux/amd64 linux/arm windows/amd64" -output="bin/{{.OS}}-{{.Arch}}/ocdev" $(BUILD_FLAGS)
.PHONY: generate-cli-docs
generate-cli-docs:
go run scripts/generate-cli-documentation.go

View File

@@ -11,3 +11,25 @@ You can [download](https://dl.bintray.com/ocdev/ocdev/latest/) latest binaries (
- make sure that ocdev binary exists in your $PATH
- copy the [plugin.yaml](./plugin.yaml) file to ~/.kube/plugins/ocdev/
- use the plugin as `oc plugin dev`
### CLI Structure
```
ocdev --verbose : OpenShift CLI for Developers
application : application
create : create an application
delete : delete the given application
get --short : get the active application
list : lists all the applications
completion : Output shell completion code
component : components of application
create --binary --dir --git : component create <component_type> [component_name]
delete : component delete <component_name>
get --short : component get
push --dir : component push
storage --component : storage
add --path --size : create storage and mount to component
list : list storage attached to a component
remove : remove storage from component
version : Print the version of ocdev
```
*_autogenerated_

47
cmd/documentation.go Normal file
View File

@@ -0,0 +1,47 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
func getFlags(flags *pflag.FlagSet) []string {
var f []string
flags.VisitAll(func(flag *pflag.Flag) {
f = append(f, fmt.Sprintf("--%v", flag.Name))
})
return f
}
func flattenFlags(flags []string) string {
var flagString string
for _, flag := range flags {
flagString = flagString + flag + " "
}
return flagString
}
func commandPrinter(command *cobra.Command, level int) string {
var finalCommand string
// add indentation
for i := 0; i < level; i++ {
finalCommand = finalCommand + " "
}
finalCommand = finalCommand +
command.Name() +
" " +
flattenFlags(getFlags(command.NonInheritedFlags())) +
": " +
command.Short +
"\n"
for _, subcommand := range command.Commands() {
finalCommand = finalCommand + commandPrinter(subcommand, level+1)
}
return finalCommand
}
func GenerateCLIDocs() string {
return commandPrinter(rootCmd, 0)
}

View File

@@ -0,0 +1,11 @@
package main
import (
"fmt"
"github.com/redhat-developer/ocdev/cmd"
)
func main() {
fmt.Print(cmd.GenerateCLIDocs())
}