Skip to content

Commit

Permalink
Simplify command line option checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Dec 23, 2012
1 parent 8aeeff7 commit 848f3c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 9 additions & 7 deletions cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,17 @@ func main() {

config, err := ss.ParseConfig(configFile)
if err != nil {
enough := enoughOptions(&cmdConfig)
if !(enough && os.IsNotExist(err)) {
config = &cmdConfig
if os.IsNotExist(err) {
if !enoughOptions(config) {
log.Println("must specify server address, password and both server/local port")
os.Exit(1)
}
log.Println("using all options from command line")
} else {
log.Printf("error reading config file: %v\n", err)
os.Exit(1)
}
if !enough {
return
}
log.Println("using all options from command line")
config = &cmdConfig
} else {
ss.UpdateConfig(config, &cmdConfig)
}
Expand Down
10 changes: 4 additions & 6 deletions cmd/shadowsocks-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,12 @@ func main() {
var err error
config, err = ss.ParseConfig(configFile)
if err != nil {
enough := enoughOptions(&cmdConfig)
if !(enough && os.IsNotExist(err)) {
if os.IsNotExist(err) {
log.Println("using all options from command line")
} else {
log.Printf("error reading %s: %v\n", configFile, err)
os.Exit(1)
}
if !enough {
return
}
log.Println("using all options from command line")
config = &cmdConfig
} else {
ss.UpdateConfig(config, &cmdConfig)
Expand Down

0 comments on commit 848f3c0

Please sign in to comment.