diff options
author | vince <vincetiu8@gmail.com> | 2020-07-14 20:43:16 +0800 |
---|---|---|
committer | vince <vincetiu8@gmail.com> | 2020-07-28 20:26:06 +0800 |
commit | da3ea0cebeaa70c3c5699af91dc189b77a572430 (patch) | |
tree | 58eaddd3922149e28a01d0f56d3a2354182a234f | |
parent | 0590de9f045c2090d72655a7c2e1d41be9b9104c (diff) | |
download | git-bug-da3ea0cebeaa70c3c5699af91dc189b77a572430.tar.gz git-bug-da3ea0cebeaa70c3c5699af91dc189b77a572430.zip |
Generate bridge configure docs on runtime
This generates the documentation for each bridge implementation at runtime.
-rw-r--r-- | bridge/core/bridge.go | 5 | ||||
-rw-r--r-- | commands/bridge_configure.go | 34 |
2 files changed, 18 insertions, 21 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index 8c1f97142..5b75fec50 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -69,6 +69,11 @@ func Targets() []string { return result } +// TargetTypes returns all types of bridge implementation target +func TargetTypes() map[string]reflect.Type { + return bridgeImpl +} + // TargetExist return true if the given target has a bridge implementation func TargetExist(target string) bool { _, ok := bridgeImpl[target] diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index ecdb6502c..278ecc74a 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "os" + "reflect" "strconv" "strings" @@ -27,11 +28,21 @@ func newBridgeConfigureCommand() *cobra.Command { env := newEnv() options := bridgeConfigureOptions{} + targetDocs := "" + for _, v := range core.TargetTypes() { + targetDocs += fmt.Sprintf("# For %s:\ngit bug bridge configure \\\n", strings.Title(strings.Split(v.String(), ".")[0])) + b := reflect.New(v).Interface().(core.BridgeImpl) + for param := range b.ValidParams() { + targetDocs += fmt.Sprintf(" --%s=Placeholder Text \\\n", strings.ToLower(param)) + } + targetDocs += "\n" + } + cmd := &cobra.Command{ Use: "configure", Short: "Configure a new bridge.", Long: ` Configure a new bridge by passing flags or/and using interactive terminal prompts. You can avoid all the terminal prompts by passing all the necessary flags to configure your bridge.`, - Example: `# Interactive example + Example: fmt.Sprintf(`# Interactive example [1]: github [2]: gitlab [3]: jira @@ -64,26 +75,7 @@ Private: Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700 Successfully configured bridge: default -# For GitHub -git bug bridge configure \ - --name=default \ - --target=github \ - --owner=$(OWNER) \ - --project=$(PROJECT) \ - --token=$(TOKEN) - -# For Launchpad -git bug bridge configure \ - --name=default \ - --target=launchpad-preview \ - --url=https://bugs.launchpad.net/ubuntu/ - -# For Gitlab -git bug bridge configure \ - --name=default \ - --target=github \ - --url=https://github.com/michaelmure/git-bug \ - --token=$(TOKEN)`, +%s`, targetDocs), PreRunE: loadBackend(env), PostRunE: closeBackend(env), RunE: func(cmd *cobra.Command, args []string) error { |