aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Murphy <[email protected]>2015-03-05 15:52:06 -0600
committerMichael Murphy <[email protected]>2015-03-05 15:52:06 -0600
commit235c2406bb1d7f5c928348aeebdac38a7673f4fb (patch)
tree02602faf287567bbad70cadd44ef038aababc51f
parentRemove \n from usageText (diff)
downloadgoupx-235c2406bb1d7f5c928348aeebdac38a7673f4fb.tar.xz
goupx-235c2406bb1d7f5c928348aeebdac38a7673f4fb.zip
Add Empty Argument Check
Print usage if no arguments are given.
-rw-r--r--main.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/main.go b/main.go
index ff0a982..40fb246 100644
--- a/main.go
+++ b/main.go
@@ -12,7 +12,8 @@ const usageText = `usage: goupx [args...] files...
--no-upx: Disables UPX from running.
--strip-binary: Strips binaries before compressing them.
-See UPX's documentation (man upx) for information on UPX's flags.`
+See UPX's documentation (man upx) for information on UPX's flags.
+`
var run_strip = false
var run_upx = true
@@ -26,6 +27,9 @@ func usage() {
// parseArguments parses arguments from os.Args and separates the goupx flags
// from the UPX flags, as well as separating the files from the arguments.
func parseArguments() (args []string, files []string) {
+ if len(os.Args) == 1 {
+ usage()
+ }
args = append(args, "/usr/bin/upx")
for _, arg := range os.Args[1:] {
switch {
@@ -48,11 +52,11 @@ func parseArguments() (args []string, files []string) {
func compressBinary(input_file string, arguments []string) {
if run_upx {
cmd := &exec.Cmd{
- Path: "/usr/bin/upx",
- Args: append(arguments, input_file),
- Stdout: os.Stdout,
- Stderr: os.Stderr,
+ Path: "/usr/bin/upx",
+ Args: append(arguments, input_file),
}
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Panic("upx failed: ", err)
}