date: Simple implementation.
This commit is contained in:
parent
58bb9ea140
commit
48e278bad9
2 changed files with 33 additions and 0 deletions
31
date/date.go
Normal file
31
date/date.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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" {
|
||||
|
|
Loading…
Reference in a new issue