Skip to content

Commit

Permalink
Merge pull request #29 from blp1526/help_message
Browse files Browse the repository at this point in the history
Add readable help
  • Loading branch information
blp1526 authored Jul 30, 2017
2 parents 9190b40 + 5a53775 commit df8233e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ $ scv is1a ubuntu

|Name|Description|
|-|-|
|--help|print help|
|--verbose|print debug log|
|--version|print version number|
|-h, --help|print help message and exit|
|-v, --verbose|print debug log|
|-V, --version|print version and exit|
35 changes: 30 additions & 5 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,50 @@ import (
var version string

const expectedArgsSize = 2
const help = `
Usage: scv [options] [zone name] [server name]
Options:
-h, --help print help message and exit
-v, --verbose print debug log
-V, --version print version and exit
`

func Run() (result string, err error) {
var optHelp bool
var optLongHelp bool
flag.BoolVar(&optHelp, "h", false, "")
flag.BoolVar(&optLongHelp, "help", false, "")

var optVersion bool
flag.BoolVar(&optVersion, "version", false, "print version number")
var optLongVersion bool
flag.BoolVar(&optVersion, "V", false, "")
flag.BoolVar(&optLongVersion, "version", false, "")

var optVerbose bool
flag.BoolVar(&optVerbose, "verbose", false, "print debug log")
var optLongVerbose bool
flag.BoolVar(&optVerbose, "v", false, "")
flag.BoolVar(&optLongVerbose, "verbose", false, "")

flag.Parse()
if optVersion {

if optHelp || optLongHelp {
return fmt.Sprintf("%s", help), err
}

if optVersion || optLongVersion {
return fmt.Sprintf("scv version %s", version), err
}

logger := &Logger{}
if optVerbose {
if optVerbose || optLongVerbose {
logger.Verbose = true
}

argsSize := len(flag.Args())
if argsSize != expectedArgsSize {
if argsSize == 0 {
return fmt.Sprintf("%s", help), err
} else if argsSize != expectedArgsSize {
return result, fmt.Errorf("Expected arguments size is %d, but given %d",
expectedArgsSize, argsSize)
}
Expand Down

0 comments on commit df8233e

Please sign in to comment.