diff --git a/date/date.go b/date/date.go new file mode 100644 index 0000000..a65f5dc --- /dev/null +++ b/date/date.go @@ -0,0 +1,31 @@ +package date + +import( + "os" + "flag" + "fmt" + "time" +) + +func Run(args []string) int { + status := 0 + arg0 := args[0] + args = args[1:] + flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) + flagSet.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage of %s: %s\n", arg0, arg0) + flagSet.PrintDefaults() + } + flagSet.Parse(args) + + if len(flagSet.Args())>0 { + flagSet.Usage() + os.Exit(1) + } + + date := time.Now() + + fmt.Println(date) + + return status +} diff --git a/goblin.go b/goblin.go index d022f8a..f56249b 100644 --- a/goblin.go +++ b/goblin.go @@ -13,6 +13,7 @@ import( "github.com/jienfak/goblin/tac" "github.com/jienfak/goblin/ls" "github.com/jienfak/goblin/yes" + "github.com/jienfak/goblin/date" ) func main() { @@ -32,6 +33,7 @@ func main() { "tac" : tac.Run, "ls" : ls.Run, "yes" : yes.Run, + "date" : date.Run, } if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {