-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mv main.go to cmd/calma/ * split file
- Loading branch information
Showing
4 changed files
with
73 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"golang.org/x/xerrors" | ||
|
||
"github.com/ddddddO/calma" | ||
) | ||
|
||
var jst = time.FixedZone("JST", +9*60*60) | ||
|
||
func main() { | ||
flag.Usage = func() { | ||
usage := "This CLI outputs Japanese calendar in Markdown. It supports national holidays.\n\nUsage of %s:\n" | ||
fmt.Fprintf(flag.CommandLine.Output(), usage, os.Args[0]) | ||
flag.PrintDefaults() | ||
} | ||
var retreat, advance int | ||
flag.IntVar(&retreat, "r", 0, "Number of months to retreat") | ||
flag.IntVar(&advance, "a", 0, "Number of months to advance") | ||
var isHTML bool | ||
flag.BoolVar(&isHTML, "html", false, "Output html") | ||
flag.Parse() | ||
|
||
if retreat != 0 && advance != 0 { | ||
fmt.Fprintln(os.Stderr, xerrors.New("Please use either")) | ||
os.Exit(1) | ||
} | ||
|
||
targetDate := time.Now().In(jst) | ||
if retreat != 0 { | ||
targetDate = targetDate.AddDate(0, -retreat, 0) | ||
} | ||
if advance != 0 { | ||
targetDate = targetDate.AddDate(0, advance, 0) | ||
} | ||
|
||
calendar, err := calma.NewCalendar(targetDate) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, xerrors.Errorf("%+v", err)) | ||
os.Exit(1) | ||
} | ||
|
||
if isHTML { | ||
html := calendar.HTML() | ||
fmt.Print(html) | ||
return | ||
} | ||
fmt.Print(calendar) | ||
} |