diff --git a/app/app.go b/app/app.go index a79f5da..bfec7fa 100644 --- a/app/app.go +++ b/app/app.go @@ -6,7 +6,7 @@ import ( "time" ) -func Character(today time.Time, config Config) (string, error) { +func Character(today time.Time, config Config) (string, string, error) { for _, rule := range config.Rules { var end time.Time @@ -18,13 +18,13 @@ func Character(today time.Time, config Config) (string, error) { weekday := time.Weekday(rule.Weekday) end = endOfNthWeekdayOfMonth(today, month, rule.Week, weekday) } else { - return "", errors.New(fmt.Sprint(rule.Name, " is not a valid rule")) + return "", "", errors.New(fmt.Sprint(rule.Name, " is not a valid rule")) } if inSeason(today, end, rule.Span) { - return rule.Emoji, nil + return rule.Emoji, rule.Name, nil } } - return config.Default, nil + return config.Default, "(default)", nil } func inSeason(today time.Time, end time.Time, spanDays int) bool { diff --git a/main.go b/main.go index 45d599f..983a0e9 100644 --- a/main.go +++ b/main.go @@ -1,25 +1,51 @@ package main import ( + "flag" "fmt" "log" "os" + "strings" "time" "github.com/lcarva/festoji/app" ) +var ( + n = flag.Int("n", 1, "number of characters/days to display") + day = flag.Bool("day", false, "display day for the character") + rule = flag.Bool("rule", false, "display matching rule for the character") +) + func main() { + flag.Parse() + userConfigPath := os.ExpandEnv("${HOME}/.festoji.yaml") config, errConfig := app.NewConfig(userConfigPath) if errConfig != nil { log.Fatal("Unable to load configuration: ", errConfig) return } - character, errChar := app.Character(time.Now(), config) - if errChar != nil { - log.Fatal("Unable to get character: ", errChar) - return + + t := time.Now() + for i := 0; i < *n; i++ { + character, ruleName, errChar := app.Character(t, config) + if errChar != nil { + log.Fatal("Unable to get character: ", errChar) + return + } + + var parts []string + if *day { + parts = append(parts, t.Format("02/Jan/2006")) + } + parts = append(parts, character) + if *rule { + parts = append(parts, ruleName) + } + fmt.Println(strings.Join(parts, " ")) + + t = t.Add(time.Hour * 24) } - fmt.Println(character) + }