Detailed changes
@@ -23,6 +23,7 @@ func Targets() []string {
return core.Targets()
}
+// ValidParams returns the valid input parameters for configuring a target bridge
func ValidParams(target string) ([]string, error) {
return core.ValidParams(target)
}
@@ -83,6 +83,7 @@ func Targets() []string {
return result
}
+// ValidParams returns the valid input parameters for configuring a target bridge
func ValidParams(target string) ([]string, error) {
validParams, ok := bridgeValidParams[target]
if !ok {
@@ -23,92 +23,6 @@ type bridgeConfigureOptions struct {
tokenStdin bool
}
-var bridgeExampleFilePath = "commands/bridge_configure_example.go"
-
-func GenBridgeConfig() error {
- var exampleText strings.Builder
- exampleText.WriteString("`")
- exampleText.WriteString(`# 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`)
- 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()
-
- _, 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{}
@@ -1,4 +1,4 @@
-// Code generated by go generate; DO NOT EDIT.
+// Code generated by doc/gen_docs.go; DO NOT EDIT.
package commands
@@ -33,35 +33,37 @@ Private:
- 'repo' : to be able to read private repositories
Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
-Successfully configured bridge: default# For Github
+Successfully configured bridge: default
+
+# For Github
git bug bridge configure \
- --URL= \
- --Login= \
- --CredPrefix= \
- --TokenRaw= \
- --Owner= \
- --Project= \
+ --TokenRaw=PLACEHOLDERTEXT \
+ --Owner=PLACEHOLDERTEXT \
+ --Project=PLACEHOLDERTEXT \
+ --URL=PLACEHOLDERTEXT \
+ --Login=PLACEHOLDERTEXT \
+ --CredPrefix=PLACEHOLDERTEXT \
# For Gitlab
git bug bridge configure \
- --BaseURL= \
- --Login= \
- --CredPrefix= \
- --TokenRaw= \
- --URL= \
+ --Login=PLACEHOLDERTEXT \
+ --CredPrefix=PLACEHOLDERTEXT \
+ --TokenRaw=PLACEHOLDERTEXT \
+ --URL=PLACEHOLDERTEXT \
+ --BaseURL=PLACEHOLDERTEXT \
# For Jira
git bug bridge configure \
- --Project= \
- --BaseURL= \
- --Login= \
- --CredPrefix= \
+ --BaseURL=PLACEHOLDERTEXT \
+ --Login=PLACEHOLDERTEXT \
+ --CredPrefix=PLACEHOLDERTEXT \
+ --Project=PLACEHOLDERTEXT \
# For Launchpad-Preview
git bug bridge configure \
- --URL= \
- --Project= \
+ --URL=PLACEHOLDERTEXT \
+ --Project=PLACEHOLDERTEXT \
`
@@ -5,18 +5,23 @@ import (
"os"
"path"
"path/filepath"
+ "strings"
"time"
+ "github.com/go-errors/errors"
"github.com/spf13/cobra/doc"
+ "github.com/MichaelMure/git-bug/bridge"
"github.com/MichaelMure/git-bug/commands"
)
+const bridgeExampleFilePath = "commands/bridge_configure_doc.go"
+
func main() {
fmt.Println("Generating documentation ...")
tasks := map[string]func() error{
- "BridgeConfig": commands.GenBridgeConfig,
+ "BridgeConfig": genBridgeConfig,
"ManPage": genManPage,
"Markdown": genMarkdown,
}
@@ -40,6 +45,92 @@ func main() {
// wg.Wait()
}
+func genBridgeConfig() error {
+ var exampleText strings.Builder
+ exampleText.WriteString("`")
+ exampleText.WriteString(`# 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
+
+`)
+ targets := bridge.Targets()
+ for i, b := range targets {
+ if i != 0 {
+ _, err := exampleText.WriteString("\n\n")
+ if err != nil {
+ return err
+ }
+ }
+ _, 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 errors.WrapPrefix(err, "bridge parameters", 0)
+ }
+ for _, param := range params {
+ _, err = fmt.Fprintf(&exampleText, " --%s=PLACEHOLDERTEXT \\\n", param)
+ if err != nil {
+ return err
+ }
+ }
+ }
+ exampleText.WriteString("`")
+
+ _ = os.Remove(bridgeExampleFilePath)
+
+ f, err := os.Create(bridgeExampleFilePath)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ _, err = f.WriteString(`// Code generated by doc/gen_docs.go; 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 genManPage() error {
cwd, _ := os.Getwd()
dir := path.Join(cwd, "doc", "man")
@@ -105,37 +105,39 @@ Private:
\- 'repo' : to be able to read private repositories
Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
-Successfully configured bridge: default# For Github
+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)= \\
+ \-\-URL= \\
+ \-\-Login= \\
+ \-\-CredPrefix= \\
+ \-\-TokenRaw= \\
+ \-\-Owner= \\
+ \-\-Project= \\
# For Gitlab
git bug bridge configure \\
- \-\-%!s(int=0)= \\
- \-\-%!s(int=1)= \\
- \-\-%!s(int=2)= \\
- \-\-%!s(int=3)= \\
- \-\-%!s(int=4)= \\
+ \-\-BaseURL= \\
+ \-\-Login= \\
+ \-\-CredPrefix= \\
+ \-\-TokenRaw= \\
+ \-\-URL= \\
# For Jira
git bug bridge configure \\
- \-\-%!s(int=0)= \\
- \-\-%!s(int=1)= \\
- \-\-%!s(int=2)= \\
- \-\-%!s(int=3)= \\
+ \-\-Project= \\
+ \-\-BaseURL= \\
+ \-\-Login= \\
+ \-\-CredPrefix= \\
# For Launchpad\-Preview
git bug bridge configure \\
- \-\-%!s(int=0)= \\
- \-\-%!s(int=1)= \\
+ \-\-URL= \\
+ \-\-Project= \\
.fi
@@ -44,37 +44,39 @@ Private:
- 'repo' : to be able to read private repositories
Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700
-Successfully configured bridge: default# For Github
+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)= \
+ --URL= \
+ --Login= \
+ --CredPrefix= \
+ --TokenRaw= \
+ --Owner= \
+ --Project= \
# For Gitlab
git bug bridge configure \
- --%!s(int=0)= \
- --%!s(int=1)= \
- --%!s(int=2)= \
- --%!s(int=3)= \
- --%!s(int=4)= \
+ --BaseURL= \
+ --Login= \
+ --CredPrefix= \
+ --TokenRaw= \
+ --URL= \
# For Jira
git bug bridge configure \
- --%!s(int=0)= \
- --%!s(int=1)= \
- --%!s(int=2)= \
- --%!s(int=3)= \
+ --Project= \
+ --BaseURL= \
+ --Login= \
+ --CredPrefix= \
# For Launchpad-Preview
git bug bridge configure \
- --%!s(int=0)= \
- --%!s(int=1)= \
+ --URL= \
+ --Project= \
```