Skip to content

Commit

Permalink
Write to os.Stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
tyru committed Sep 21, 2017
1 parent eca52c5 commit 42cf115
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
27 changes: 14 additions & 13 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,36 @@ func Get(args []string) int {
// Parse args
args, flags, err := cmd.parseArgs(args)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
fmt.Println(err.Error())
return 10
}

// Read lock.json
lockJSON, err := lockjson.Read()
if err != nil {
fmt.Fprintln(os.Stderr, "[ERROR] Could not read lock.json: "+err.Error())
fmt.Println("[ERROR] Could not read lock.json: " + err.Error())
return 11
}

reposPathList, err := cmd.getReposPathList(flags, args, lockJSON)
if err != nil {
fmt.Fprintln(os.Stderr, "[ERROR] Could not get repos list: "+err.Error())
fmt.Println("[ERROR] Could not get repos list: " + err.Error())
return 12
}

// Check if any repositories are dirty
for _, reposPath := range reposPathList {
fullpath := pathutil.FullReposPathOf(reposPath)
if cmd.pathExists(fullpath) && cmd.isDirtyWorktree(fullpath) {
fmt.Fprintln(os.Stderr, "[ERROR] Repository has dirty worktree: "+fullpath)
fmt.Println("[ERROR] Repository has dirty worktree: " + fullpath)
return 13
}
}

// Begin transaction
err = transaction.Create()
if err != nil {
fmt.Fprintln(os.Stderr, "[ERROR] Failed to begin transaction: "+err.Error())
fmt.Println("[ERROR] Failed to begin transaction: " + err.Error())
return 14
}
defer transaction.Remove()
Expand All @@ -77,7 +77,7 @@ func Get(args []string) int {
// Get HEAD hash string
hash, err := cmd.getHEADHashString(reposPath)
if err != nil {
fmt.Fprintln(os.Stderr, "[ERROR] Failed to get HEAD commit hash: "+err.Error())
fmt.Println("[ERROR] Failed to get HEAD commit hash: " + err.Error())
continue
}
// Update repos[]/trx_id, repos[]/version
Expand All @@ -88,24 +88,24 @@ func Get(args []string) int {
upgradedList = append(upgradedList, reposPath)
}
} else {
fmt.Fprintln(os.Stderr, "[ERROR] Failed to install / upgrade plugins: "+err.Error())
fmt.Println("[ERROR] Failed to install / upgrade plugins: " + err.Error())
}
}

if updatedLockJSON {
err = lockjson.Write(lockJSON)
if err != nil {
fmt.Fprintln(os.Stderr, "[ERROR] Could not write to lock.json: "+err.Error())
fmt.Println("[ERROR] Could not write to lock.json: " + err.Error())
return 15
}
}

// Show upgraded plugins
if len(upgradedList) > 0 {
fmt.Fprintln(os.Stderr, "[WARN] Reloading upgraded plugin is not supported.")
fmt.Fprintln(os.Stderr, "[WARN] Please restart your Vim to reload the following plugins:")
fmt.Println("[WARN] Reloading upgraded plugin is not supported.")
fmt.Println("[WARN] Please restart your Vim to reload the following plugins:")
for _, reposPath := range upgradedList {
fmt.Fprintln(os.Stderr, "[WARN] "+reposPath)
fmt.Println("[WARN] " + reposPath)
}
}

Expand All @@ -115,8 +115,9 @@ func Get(args []string) int {
func (getCmd) parseArgs(args []string) ([]string, *getFlags, error) {
var flags getFlags
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
fs.SetOutput(os.Stdout)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, `
fmt.Println(`
Usage
volt get [-help] [-l] [-u] [-v] [{repository} ...]
Expand All @@ -125,7 +126,7 @@ Description
Options`)
fs.PrintDefaults()
fmt.Fprintln(os.Stderr)
fmt.Println()
}
fs.BoolVar(&flags.lockJSON, "l", false, "from lock.json")
fs.BoolVar(&flags.upgrade, "u", false, "upgrade installed vim plugin")
Expand Down
13 changes: 7 additions & 6 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ func Query(args []string) int {

args, flags, err := cmd.parseArgs(args)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
fmt.Println(err.Error())
return 10
}

// Read lock.json
lockJSON, err := lockjson.Read()
if err != nil {
fmt.Fprintln(os.Stderr, "[ERROR] Failed to read lock.json: "+err.Error())
fmt.Println("[ERROR] Failed to read lock.json: " + err.Error())
return 11
}

reposPathList, err := cmd.getReposPathList(flags, args, lockJSON)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
fmt.Println(err.Error())
return 12
}

reposList := make([]lockjson.Repos, 0, len(reposPathList))
for _, reposPath := range reposPathList {
repos, err := cmd.lookUpRepos(reposPath, lockJSON)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to look up '"+reposPath+"': "+err.Error())
fmt.Println("Failed to look up '" + reposPath + "': " + err.Error())
return 13
}
reposList = append(reposList, *repos)
Expand All @@ -58,8 +58,9 @@ func Query(args []string) int {
func (queryCmd) parseArgs(args []string) ([]string, *queryFlags, error) {
var flags queryFlags
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
fs.SetOutput(os.Stdout)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, `
fmt.Println(`
Usage
volt query [-help] [-j] [-i] [{repository}]
Expand All @@ -68,7 +69,7 @@ Description
Options`)
fs.PrintDefaults()
fmt.Fprintln(os.Stderr)
fmt.Println()
}
fs.BoolVar(&flags.json, "j", false, "output as JSON")
fs.BoolVar(&flags.installed, "i", false, "show installed info")
Expand Down
9 changes: 5 additions & 4 deletions cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func Rm(args []string) int {

reposPath, flags, err := cmd.parseArgs(args)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
fmt.Println(err.Error())
return 10
}

err = cmd.removeRepos(reposPath, flags)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to clone repository: "+err.Error())
fmt.Println("Failed to clone repository: " + err.Error())
return 11
}

Expand All @@ -37,8 +37,9 @@ func Rm(args []string) int {
func (rmCmd) parseArgs(args []string) (string, *rmFlags, error) {
var flags rmFlags
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
fs.SetOutput(os.Stdout)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, `
fmt.Println(`
Usage
volt rm [-help] [-p] {repository}
Expand All @@ -47,7 +48,7 @@ Description
Options`)
fs.PrintDefaults()
fmt.Fprintln(os.Stderr)
fmt.Println()
}
fs.BoolVar(&flags.removePlugConf, "p", false, "Remove plugconf")
fs.Parse(args)
Expand Down

0 comments on commit 42cf115

Please sign in to comment.