diff --git a/README.md b/README.md index 01d8e7c..7fb8b89 100644 --- a/README.md +++ b/README.md @@ -249,10 +249,14 @@ Available Commands: post Post astronomical calendar data to TL Flags: + --eclipse output eclipse --end string end of date (YYYY-MM-DD) - --ephemeris output ephemeris + --ephemeris-all output all ephemeris -h, --help help for calendar --holiday output holiday + --moon-phase output moon-phase + --planet output planet + --solar-term output solar-term --start string start of date (YYYY-MM-DD) --template string template file for Output format diff --git a/calendar/calendar.go b/calendar/calendar.go index f8c59a6..38008e9 100644 --- a/calendar/calendar.go +++ b/calendar/calendar.go @@ -20,14 +20,18 @@ const defaultTemplate = `{{ range . }}{{ .Date }} {{ .Title }} // Config type is configurations for calendar package. type Config struct { - start, end value.DateJp - holiday, ephemeris bool - tempDir *tempdir.TempDir - templateFile string + start, end value.DateJp + holiday bool + moonPhase bool + solarTerm bool + eclipse bool + planet bool + tempDir *tempdir.TempDir + templateFile string } // NewConfig function creates new Config instance. -func NewConfig(start, end string, holiday, ephemeris bool, tempDir *tempdir.TempDir, templateFile string) (*Config, error) { +func NewConfig(start, end string, holiday, moonPhase, solarTerm, eclipse, planet bool, tempDir *tempdir.TempDir, templateFile string) (*Config, error) { startdate := value.NewDate(time.Time{}) enddate := value.NewDate(time.Time{}) if len(start) == 0 && len(end) == 0 { @@ -38,14 +42,32 @@ func NewConfig(start, end string, holiday, ephemeris bool, tempDir *tempdir.Temp if len(start) > 0 { dt, err := value.DateFrom(start) if err != nil { - return nil, errs.Wrap(err, errs.WithContext("start", start), errs.WithContext("end", end), errs.WithContext("holiday", holiday), errs.WithContext("ephemeris", ephemeris), errs.WithContext("templateFile", templateFile)) + return nil, errs.Wrap( + err, + errs.WithContext("start", start), + errs.WithContext("end", end), + errs.WithContext("holiday", holiday), + errs.WithContext("moonPhase", moonPhase), + errs.WithContext("solarTerm", solarTerm), + errs.WithContext("eclipse", eclipse), + errs.WithContext("planet", planet), + errs.WithContext("templateFile", templateFile)) } startdate = dt } if len(start) > 0 { dt, err := value.DateFrom(end) if err != nil { - return nil, errs.Wrap(err, errs.WithContext("start", start), errs.WithContext("end", end), errs.WithContext("holiday", holiday), errs.WithContext("ephemeris", ephemeris), errs.WithContext("templateFile", templateFile)) + return nil, errs.Wrap( + err, + errs.WithContext("start", start), + errs.WithContext("end", end), + errs.WithContext("holiday", holiday), + errs.WithContext("moonPhase", moonPhase), + errs.WithContext("solarTerm", solarTerm), + errs.WithContext("eclipse", eclipse), + errs.WithContext("planet", planet), + errs.WithContext("templateFile", templateFile)) } enddate = dt } @@ -54,7 +76,10 @@ func NewConfig(start, end string, holiday, ephemeris bool, tempDir *tempdir.Temp start: startdate, end: enddate, holiday: holiday, - ephemeris: ephemeris, + moonPhase: moonPhase, + solarTerm: solarTerm, + eclipse: eclipse, + planet: planet, tempDir: tempDir, templateFile: templateFile, }, nil @@ -106,8 +131,17 @@ func (cal *Config) GetEvents() ([]koyomi.Event, error) { if cal.holiday { ids = append(ids, koyomi.Holiday) } - if cal.ephemeris { - ids = append(ids, koyomi.MoonPhase, koyomi.SolarTerm, koyomi.Eclipse, koyomi.Planet) + if cal.moonPhase { + ids = append(ids, koyomi.MoonPhase) + } + if cal.solarTerm { + ids = append(ids, koyomi.SolarTerm) + } + if cal.eclipse { + ids = append(ids, koyomi.Eclipse) + } + if cal.planet { + ids = append(ids, koyomi.Planet) } if len(ids) == 0 { return []koyomi.Event{}, nil diff --git a/facade/calendar.go b/facade/calendar.go index 5da1b89..54c1b64 100644 --- a/facade/calendar.go +++ b/facade/calendar.go @@ -22,7 +22,11 @@ func newCalendarCmd(ui *rwi.RWI) *cobra.Command { calendarCmd.PersistentFlags().StringP("start", "", "", "start of date (YYYY-MM-DD)") calendarCmd.PersistentFlags().StringP("end", "", "", "end of date (YYYY-MM-DD)") calendarCmd.PersistentFlags().BoolP("holiday", "", false, "output holiday") - calendarCmd.PersistentFlags().BoolP("ephemeris", "", false, "output ephemeris") + calendarCmd.PersistentFlags().BoolP("ephemeris-all", "", false, "output all ephemeris") + calendarCmd.PersistentFlags().BoolP("moon-phase", "", false, "output moon-phase") + calendarCmd.PersistentFlags().BoolP("solar-term", "", false, "output solar-term") + calendarCmd.PersistentFlags().BoolP("eclipse", "", false, "output eclipse") + calendarCmd.PersistentFlags().BoolP("planet", "", false, "output planet") calendarCmd.PersistentFlags().StringP("template", "", "", "template file for Output format") calendarCmd.AddCommand( @@ -45,15 +49,37 @@ func getCalendarConfig(cmd *cobra.Command, gopts *globalOptions) (*calendar.Conf if err != nil { return nil, errs.Wrap(err) } - ephemerisFlag, err := cmd.Flags().GetBool("ephemeris") + moonPhaseFlag, err := cmd.Flags().GetBool("moon-phase") if err != nil { return nil, errs.Wrap(err) } + solarTermFlag, err := cmd.Flags().GetBool("solar-term") + if err != nil { + return nil, errs.Wrap(err) + } + eclipseFlag, err := cmd.Flags().GetBool("eclipse") + if err != nil { + return nil, errs.Wrap(err) + } + planetFlag, err := cmd.Flags().GetBool("planet") + if err != nil { + return nil, errs.Wrap(err) + } + ephemerisAllFlag, err := cmd.Flags().GetBool("ephemeris-all") + if err != nil { + return nil, errs.Wrap(err) + } + if ephemerisAllFlag { + moonPhaseFlag = true + solarTermFlag = true + eclipseFlag = true + planetFlag = true + } templateFile, err := cmd.Flags().GetString("template") if err != nil { return nil, errs.Wrap(err) } - return calendar.NewConfig(start, end, holidayFlag, ephemerisFlag, gopts.TempDir, templateFile) + return calendar.NewConfig(start, end, holidayFlag, moonPhaseFlag, solarTermFlag, eclipseFlag, planetFlag, gopts.TempDir, templateFile) } /* Copyright 2024 Spiegel