Skip to content

Commit

Permalink
Add templated output to bitbucket repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofranssen committed Aug 13, 2020
1 parent b6c1b39 commit f023375
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/cmd_bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cmd

import (
"fmt"
"html/template"
"io"
"io/ioutil"
"text/tabwriter"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -71,6 +73,12 @@ func createBitbucket() *cli.Command {
EnvVars: []string{"TABIA_OUTPUT_FORMAT"},
DefaultText: "",
},
&cli.PathFlag{
Name: "template",
Aliases: []string{"T"},
Usage: "Formats output using the given `TEMPLATE`",
TakesFile: true,
},
},
},
},
Expand Down Expand Up @@ -157,6 +165,24 @@ func bitbucketRepositories(c *cli.Context) error {
if err != nil {
return err
}
case "templated":
if !c.IsSet("template") {
return fmt.Errorf("you must specify the path to the template")
}

templateFile := c.Path("template")
tmplContent, err := ioutil.ReadFile(templateFile)
if err != nil {
return err
}
tmpl, err := template.New("repositories").Parse(string(tmplContent))
if err != nil {
return err
}
err = tmpl.Execute(c.App.Writer, results)
if err != nil {
return err
}
default:
w := tabwriter.NewWriter(c.App.Writer, 3, 0, 2, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "Project\tID\tSlug\tName\tPublic\tClone")
Expand Down

0 comments on commit f023375

Please sign in to comment.