Skip to content

Commit

Permalink
Use positional args for gig instead of flag
Browse files Browse the repository at this point in the history
  • Loading branch information
laenzlinger committed Mar 31, 2024
1 parent 61af3ef commit baab917
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ test: ## run tests

integration-test: clean docker-build
$(RUN) generate sheet --band Band --all
$(RUN) generate sheet --band Band --gig "Grand Ole Opry"
$(RUN) generate list --band Band --gig "Grand Ole Opry"
$(RUN) generate sheet --band Band "Grand Ole Opry"
$(RUN) generate list --band Band "Grand Ole Opry"
ls -lart test/Repertoire/out

lint: ## lint source code
Expand Down
8 changes: 4 additions & 4 deletions cmd/generate_setlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import (
var setlistCmd = &cobra.Command{
Use: "list",
Short: "Generate a Setlist",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Long: `Generates a Setlist for a Gig.
`,
Run: func(_ *cobra.Command, _ []string) {
err := generateSetlist()
Run: func(_ *cobra.Command, args []string) {
err := generateSetlist(args[0])
cobra.CheckErr(err)
},
}
Expand All @@ -51,9 +52,8 @@ func init() {
cobra.CheckErr(err)
}

func generateSetlist() error {
func generateSetlist(gigName string) error {
band := viper.GetString("band.name")
gigName := viper.GetString("gig.name")
include := viper.GetStringSlice("setlist.include-columns")

rep, err := repertoire.New(band)
Expand Down
24 changes: 10 additions & 14 deletions cmd/generate_sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,28 @@ import (
//nolint:gochecknoglobals // cobra is designed like this
var sheetCmd = &cobra.Command{
Use: "sheet",
Short: "Generate a Cheat Sheet",
Long: `Generates a Cheat Sheet for a Gig.
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs),
Short: "Generate a cheat sheet",
Long: `Generates a cheat sheet for a Gig or for all songs.
Currently supports pdf sheets.
The pdf sheets are optionally generated for odf files.
`,
Run: func(cmd *cobra.Command, _ []string) {
Run: func(cmd *cobra.Command, args []string) {
band := viper.GetString("band.name")
all, err := cmd.Flags().GetBool("all")
if err != nil {
log.Fatal(err)
}
cobra.CheckErr(err)
if all {
err = sheet.AllForBand(band)
} else {
gigName := viper.GetString("gig.name")
gig, e := gig.New(band, gigName)
if e != nil {
log.Fatal(e)
if len(args) == 0 {
log.Fatal("gig name not provided")
}
gig, e := gig.New(band, args[0])
cobra.CheckErr(e)
err = sheet.ForGig(band, gig)
}
if err != nil {
log.Fatal(err)
}

cobra.CheckErr(err)
},
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func init() {
rootCmd.PersistentFlags().StringP("band", "b", "", "root directory of the repertoire db")
err := viper.BindPFlag("band.name", rootCmd.PersistentFlags().Lookup("band"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().StringP("gig", "g", "", "name of the gig")
err = viper.BindPFlag("gig.name", rootCmd.PersistentFlags().Lookup("gig"))
cobra.CheckErr(err)
}

// initConfig reads in config file and ENV variables if set.
Expand Down

0 comments on commit baab917

Please sign in to comment.