summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-07-27 02:07:26 +0700
committerShulhan <ms@kilabit.info>2022-07-27 02:08:10 +0700
commitebfa0f31abcacb1120461dcad12243eed719383f (patch)
treec381929df6afd1e8e04eb0472cdb2fb125d73a2f
parent04e5792a57a40c21acfefcdb6e15cc75a281fe25 (diff)
downloadpakakeh.go-ebfa0f31abcacb1120461dcad12243eed719383f.tar.xz
cmd/xtrk: add command "help" and "version"
-rw-r--r--cmd/xtrk/main.go37
1 files changed, 31 insertions, 6 deletions
diff --git a/cmd/xtrk/main.go b/cmd/xtrk/main.go
index 10e8ff3b..658ad258 100644
--- a/cmd/xtrk/main.go
+++ b/cmd/xtrk/main.go
@@ -1,3 +1,10 @@
+// Copyright 2022, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Command xtrk is command line interface to uncompress and/or unarchive a
+// file.
+// Supported format: bzip2, gzip, tar, zip, tar.bz2, tar.gz.
package main
import (
@@ -5,29 +12,48 @@ import (
"fmt"
"log"
"os"
+ "strings"
+ "github.com/shuLhan/share"
libos "github.com/shuLhan/share/lib/os"
)
+const (
+ cmdHelp = "help"
+ cmdVersion = "version"
+)
+
func main() {
log.SetPrefix("xtrk: ")
-
log.SetFlags(0)
flag.Parse()
var (
- args = flag.Args()
+ args = flag.Args()
+
+ cmd string
fileIn string
dirOut string
err error
)
- switch len(args) {
- case 0:
+ if len(args) == 0 {
usage()
os.Exit(1)
+ }
+
+ cmd = strings.ToLower(args[0])
+ if cmd == cmdHelp {
+ usage()
+ return
+ }
+ if cmd == cmdVersion {
+ fmt.Println("xtrk v" + share.Version)
+ return
+ }
+ switch len(args) {
case 1:
fileIn = args[0]
@@ -50,8 +76,7 @@ func main() {
}
func usage() {
- fmt.Printf(`
-= xtrk
+ fmt.Printf(`= xtrk
xtrk is command line interface to uncompress and/or unarchive a file.