@@ -53,10 +53,13 @@ func Register(impl BridgeImpl) {
if bridgeLoginMetaKey == nil {
bridgeLoginMetaKey = make(map[string]string)
}
+ if bridgeValidParams == nil {
+ bridgeValidParams = make(map[string][]string)
+ }
bridgeImpl[impl.Target()] = reflect.TypeOf(impl).Elem()
bridgeLoginMetaKey[impl.Target()] = impl.LoginMetaKey()
- paramMap := bridgeImpl[impl.Target()].(BridgeImpl).ValidParams()
+ paramMap := reflect.New(bridgeImpl[impl.Target()]).Interface().(BridgeImpl).ValidParams()
params := make([]string, len(paramMap))
i := 0
@@ -23,17 +23,12 @@ type bridgeConfigureOptions struct {
tokenStdin bool
}
-func newBridgeConfigureCommand() *cobra.Command {
- env := newEnv()
- options := bridgeConfigureOptions{}
+var bridgeExampleFilePath = "commands/bridge_configure_example.go"
- targetDocs := ""
-
- 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: fmt.Sprintf(`# Interactive example
+func GenBridgeConfig() error {
+ var exampleText strings.Builder
+ exampleText.WriteString("`")
+ exampleText.WriteString(`# Interactive example
[1]: github
[2]: gitlab
[3]: jira
@@ -64,9 +59,65 @@ Private:
- 'repo' : to be able to read private repositories
Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
-Successfully configured bridge: default
+Successfully configured bridge: default`)
+ targets := bridge.Targets()
+ for i, b := range targets {
+ _, err := fmt.Fprintf(&exampleText, "# For %s\ngit bug bridge configure \\\n", strings.Title(strings.Split(b, ".")[0]))
+ if err != nil {
+ return err
+ }
+ params, err := bridge.ValidParams(b)
+ if err != nil {
+ return fmt.Errorf("Encountered error when getting bridge parameters: %q", err)
+ }
+ for _, param := range params {
+ _, err = fmt.Fprintf(&exampleText, " --%s=PLACEHOLDERTEXT \\\n", param)
+ if err != nil {
+ return err
+ }
+ }
+ if i < len(targets)-1 {
+ _, err = fmt.Fprintf(&exampleText, "\n\n")
+ if err != nil {
+ return err
+ }
+ }
+ }
+ exampleText.WriteString("`")
+
+ _ = os.Remove(bridgeExampleFilePath)
+
+ f, err := os.Create(bridgeExampleFilePath)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
-%s`, targetDocs),
+ _, err = f.WriteString(`// Code generated by go generate; DO NOT EDIT.
+
+package commands
+
+var bridgeConfigureExample =`)
+ if err != nil {
+ return err
+ }
+ _, err = f.WriteString(exampleText.String())
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func newBridgeConfigureCommand() *cobra.Command {
+ env := newEnv()
+ options := bridgeConfigureOptions{}
+
+ 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: bridgeConfigureExample,
PreRunE: loadBackend(env),
PostRunE: closeBackend(env),
RunE: func(cmd *cobra.Command, args []string) error {
@@ -0,0 +1,67 @@
+// Code generated by go generate; DO NOT EDIT.
+
+package commands
+
+var bridgeConfigureExample = `# Interactive example
+[1]: github
+[2]: gitlab
+[3]: jira
+[4]: launchpad-preview
+
+target: 1
+name [default]: default
+
+Detected projects:
+[1]: github.com/a-hilaly/git-bug
+[2]: github.com/MichaelMure/git-bug
+
+[0]: Another project
+
+Select option: 1
+
+[1]: user provided token
+[2]: interactive token creation
+Select option: 1
+
+You can generate a new token by visiting https://github.com/settings/tokens.
+Choose 'Generate new token' and set the necessary access scope for your repository.
+
+The access scope depend on the type of repository.
+Public:
+ - 'public_repo': to be able to read public repositories
+Private:
+ - 'repo' : to be able to read private repositories
+
+Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
+Successfully configured bridge: default# For Github
+git bug bridge configure \
+ --URL= \
+ --Login= \
+ --CredPrefix= \
+ --TokenRaw= \
+ --Owner= \
+ --Project= \
+
+
+# For Gitlab
+git bug bridge configure \
+ --BaseURL= \
+ --Login= \
+ --CredPrefix= \
+ --TokenRaw= \
+ --URL= \
+
+
+# For Jira
+git bug bridge configure \
+ --Project= \
+ --BaseURL= \
+ --Login= \
+ --CredPrefix= \
+
+
+# For Launchpad-Preview
+git bug bridge configure \
+ --URL= \
+ --Project= \
+`
@@ -16,8 +16,9 @@ func main() {
fmt.Println("Generating documentation ...")
tasks := map[string]func() error{
- "ManPage": genManPage,
- "Markdown": genMarkdown,
+ "BridgeConfig": commands.GenBridgeConfig,
+ "ManPage": genManPage,
+ "Markdown": genMarkdown,
}
// Due to concurrency issues in cobra, the following can't be concurrent :(
@@ -105,28 +105,38 @@ Private:
\- 'repo' : to be able to read private repositories
Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
-Successfully configured bridge: default
+Successfully configured bridge: default# For Github
+git bug bridge configure \\
+ \-\-%!s(int=0)= \\
+ \-\-%!s(int=1)= \\
+ \-\-%!s(int=2)= \\
+ \-\-%!s(int=3)= \\
+ \-\-%!s(int=4)= \\
+ \-\-%!s(int=5)= \\
+
-# For GitHub
+# For Gitlab
git bug bridge configure \\
- \-\-name=default \\
- \-\-target=github \\
- \-\-owner=$(OWNER) \\
- \-\-project=$(PROJECT) \\
- \-\-token=$(TOKEN)
+ \-\-%!s(int=0)= \\
+ \-\-%!s(int=1)= \\
+ \-\-%!s(int=2)= \\
+ \-\-%!s(int=3)= \\
+ \-\-%!s(int=4)= \\
+
-# For Launchpad
+# For Jira
git bug bridge configure \\
- \-\-name=default \\
- \-\-target=launchpad\-preview \\
- \-\-url=https://bugs.launchpad.net/ubuntu/
+ \-\-%!s(int=0)= \\
+ \-\-%!s(int=1)= \\
+ \-\-%!s(int=2)= \\
+ \-\-%!s(int=3)= \\
-# For Gitlab
+
+# For Launchpad\-Preview
git bug bridge configure \\
- \-\-name=default \\
- \-\-target=github \\
- \-\-url=https://github.com/michaelmure/git\-bug \\
- \-\-token=$(TOKEN)
+ \-\-%!s(int=0)= \\
+ \-\-%!s(int=1)= \\
+
.fi
.RE
@@ -44,28 +44,38 @@ Private:
- 'repo' : to be able to read private repositories
Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
-Successfully configured bridge: default
+Successfully configured bridge: default# For Github
+git bug bridge configure \
+ --%!s(int=0)= \
+ --%!s(int=1)= \
+ --%!s(int=2)= \
+ --%!s(int=3)= \
+ --%!s(int=4)= \
+ --%!s(int=5)= \
+
-# For GitHub
+# For Gitlab
git bug bridge configure \
- --name=default \
- --target=github \
- --owner=$(OWNER) \
- --project=$(PROJECT) \
- --token=$(TOKEN)
+ --%!s(int=0)= \
+ --%!s(int=1)= \
+ --%!s(int=2)= \
+ --%!s(int=3)= \
+ --%!s(int=4)= \
+
-# For Launchpad
+# For Jira
git bug bridge configure \
- --name=default \
- --target=launchpad-preview \
- --url=https://bugs.launchpad.net/ubuntu/
+ --%!s(int=0)= \
+ --%!s(int=1)= \
+ --%!s(int=2)= \
+ --%!s(int=3)= \
-# For Gitlab
+
+# For Launchpad-Preview
git bug bridge configure \
- --name=default \
- --target=github \
- --url=https://github.com/michaelmure/git-bug \
- --token=$(TOKEN)
+ --%!s(int=0)= \
+ --%!s(int=1)= \
+
```
### Options