mirror of
				https://github.com/redhat-developer/odo.git
				synced 2025-10-19 03:06:19 +03:00 
			
		
		
		
	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:
		
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							@@ -46,3 +46,7 @@ test-coverage:
 | 
			
		||||
.PHONY: cross
 | 
			
		||||
cross:
 | 
			
		||||
	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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							@@ -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
									
								
							
							
						
						
									
										47
									
								
								cmd/documentation.go
									
									
									
									
									
										Normal 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)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								scripts/generate-cli-documentation.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								scripts/generate-cli-documentation.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/redhat-developer/ocdev/cmd"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	fmt.Print(cmd.GenerateCLIDocs())
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user