| |
@@ -6,10 +6,13 @@
|
| |
"os"
|
| |
"regexp"
|
| |
"sort"
|
| |
+ "strconv"
|
| |
"strings"
|
| |
+ "text/template"
|
| |
|
| |
- "pagure.io/golist/pkg/util"
|
| |
"github.com/urfave/cli"
|
| |
+
|
| |
+ "pagure.io/golist/pkg/util"
|
| |
)
|
| |
|
| |
// TODO(jchaloup):
|
| |
@@ -74,6 +77,19 @@
|
| |
Name: "json",
|
| |
Usage: "Output as JSON artefact",
|
| |
},
|
| |
+ cli.StringFlag{
|
| |
+ Name: "template",
|
| |
+ Usage: "Template used to print output",
|
| |
+ Value: `{{.}}\n`,
|
| |
+ },
|
| |
+ }
|
| |
+
|
| |
+ getTemplate := func(output_fmt string) (*template.Template, error) {
|
| |
+ str, err := strconv.Unquote(`"` + output_fmt + `"`)
|
| |
+ if err != nil {
|
| |
+ return nil, fmt.Errorf("Unparseable template string: %v", err)
|
| |
+ }
|
| |
+ return template.New("output").Parse(str)
|
| |
}
|
| |
|
| |
app.Action = func(c *cli.Context) error {
|
| |
@@ -86,6 +102,11 @@
|
| |
return fmt.Errorf("At least one of --provided, --imported, --to-install or --json must be set")
|
| |
}
|
| |
|
| |
+ tmpl, err := getTemplate(c.String("template"))
|
| |
+ if err != nil {
|
| |
+ return err
|
| |
+ }
|
| |
+
|
| |
ignore := &util.Ignore{}
|
| |
|
| |
for _, dir := range c.StringSlice("ignore-tree") {
|
| |
@@ -129,7 +150,10 @@
|
| |
}
|
| |
sort.Strings(pkgs)
|
| |
for _, item := range pkgs {
|
| |
- fmt.Println(item)
|
| |
+ err := tmpl.Execute(os.Stdout, item)
|
| |
+ if err != nil {
|
| |
+ return err
|
| |
+ }
|
| |
}
|
| |
return nil
|
| |
}
|
| |
@@ -141,7 +165,10 @@
|
| |
}
|
| |
sort.Strings(pkgs)
|
| |
for _, item := range pkgs {
|
| |
- fmt.Println(item)
|
| |
+ err := tmpl.Execute(os.Stdout, item)
|
| |
+ if err != nil {
|
| |
+ return err
|
| |
+ }
|
| |
}
|
| |
return nil
|
| |
}
|
| |
@@ -153,7 +180,10 @@
|
| |
}
|
| |
sort.Strings(pkgs)
|
| |
for _, item := range pkgs {
|
| |
- fmt.Println(item)
|
| |
+ err := tmpl.Execute(os.Stdout, item)
|
| |
+ if err != nil {
|
| |
+ return err
|
| |
+ }
|
| |
}
|
| |
return nil
|
| |
}
|
| |
This adds an option
--templatethat is used to determine how output is printed. The given format string is first unquoted (to allow for things like\n) and then passed to Go's builtin templater. This is pretty powerful, but for now, I've just passed the strings that would normally be printed. You can now do something like:$ golist --package-path pagure.io/golist --imported \ --template 'BuildRequires: golang({{.}})\n' BuildRequires: golang(github.com/urfave/cli) BuildRequires: golang(pagure.io/golist/pkg/util)It may be possible to insert additional information there, if I pass something more featureful than just the name, but this is probably enough to fix #13.