Skip to content

Commit

Permalink
new: option to prepend banner on top of the output
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
  • Loading branch information
leodido committed Dec 17, 2020
1 parent 0aa570e commit f2ca6b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 26 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"bufio"
"fmt"
"os"
"time"

"github.com/leodido/maintainers-generator/pkg/version"

"github.com/sirupsen/logrus"
"k8s.io/test-infra/prow/config/secret"
)

var defaultBanner = "# Do not edit this file manually.\n# Made using github.com/leodido/mantainers-generator"

func main() {
o := NewOptions()
// Early exit in case user wants to only know the version
Expand Down Expand Up @@ -71,12 +74,33 @@ func main() {
}

w := bufio.NewWriter(output)
n, err := w.WriteString(out)

n1 := 0
if o.banner {
dt := time.Now()
n1, err = w.WriteString(
fmt.Sprintf(
"%s on %d-%02d-%02dT%02d:%02d:%02d\n",
defaultBanner,
dt.Year(),
dt.Month(),
dt.Day(),
dt.Hour(),
dt.Minute(),
dt.Second(),
),
)
if err != nil {
logrus.WithError(err).WithField("output", o.outputFile).Fatal("Unable to write output file.")
}
}

n2, err := w.WriteString(out)
if err != nil {
logrus.WithError(err).WithField("output", o.outputFile).Fatal("Unable to write output file.")
}
w.Flush()
if o.outputFile != "stdout" {
logrus.WithField("no. of bytes", n).Info("Wrote output file.")
logrus.WithField("no. of bytes", n1+n2).Info("Wrote output file.")
}
}
6 changes: 3 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
type Options struct {
dryRun bool
github prowflagutil.GitHubOptions
hmacSecret string
version bool
logLevel string
org string
Expand All @@ -25,6 +24,7 @@ type Options struct {
personsFile string
outputFile string
personsSupport bool
banner bool
}

// Validate validates the receiving options.
Expand Down Expand Up @@ -68,8 +68,7 @@ func (o *Options) Validate() error {
func NewOptions() *Options {
o := Options{}
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
fs.BoolVar(&o.dryRun, "dry-run", true, "Dry run for testing (uses API tokens but does not mutate).")
fs.StringVar(&o.hmacSecret, "hmac", "/etc/webhook/hmac", "Path to the file containing the GitHub HMAC secret.")
fs.BoolVar(&o.dryRun, "dry-run", false, "Dry run for testing (uses API tokens but does not mutate).")
fs.BoolVar(&o.version, "version", false, "Print the version.")
fs.BoolVar(&o.dedupe, "dedupe", true, "Whether to dedupe or not sub-project areas for every maintainer.")
fs.BoolVar(&o.sort, "sort", true, "Whether to sort the projects alphabetically.")
Expand All @@ -80,6 +79,7 @@ func NewOptions() *Options {
fs.StringVar(&o.repo, "repo", "", "The GitHub repository name.")
fs.StringVar(&o.personsFile, "persons-db", "data/data.json", "The path to a JSON file containing handle => name/company mappings")
fs.StringVar(&o.outputFile, "output", "stdout", "The path where to write the output YAML maintainers")
fs.BoolVar(&o.banner, "banner", false, "Whether you want a header on top of the output YAML maintainers file")

for _, group := range []flagutil.OptionGroup{&o.github} {
group.AddFlags(fs)
Expand Down

0 comments on commit f2ca6b2

Please sign in to comment.