Skip to content

Commit

Permalink
chore: follow Go idiom: use long lines
Browse files Browse the repository at this point in the history
I will probably go back and forth about this forever.
  • Loading branch information
telemachus committed Dec 1, 2024
1 parent 408eaef commit 6aedc8e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 81 deletions.
24 changes: 3 additions & 21 deletions internal/cli/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ func (app *appEnv) clone(repos []Repo) {
}
err := os.MkdirAll(filepath.Join(app.homeDir, defaultStorage), os.ModePerm)
if err != nil {
fmt.Fprintf(
os.Stderr,
"%s %s: %s\n",
app.cmd,
app.subCmd,
err,
)
fmt.Fprintf(os.Stderr, "%s %s: %s\n", app.cmd, app.subCmd, err)
app.exitValue = exitFailure
return
}
Expand All @@ -46,13 +40,7 @@ func (app *appEnv) cloneOne(repo Repo, ch chan<- result) {
prettyPath := app.prettyPath(storagePath)
ch <- result{
isErr: false,
msg: fmt.Sprintf(
"%s %s: %s already present in %s",
app.cmd,
app.subCmd,
repo.Name,
prettyPath,
),
msg: fmt.Sprintf("%s %s: %s already present in %s", app.cmd, app.subCmd, repo.Name, prettyPath),
}
return
}
Expand All @@ -67,13 +55,7 @@ func (app *appEnv) cloneOne(repo Repo, ch chan<- result) {
app.exitValue = exitFailure
ch <- result{
isErr: true,
msg: fmt.Sprintf(
"%s %s: %s: %s",
app.cmd,
app.subCmd,
repo.Name,
err,
),
msg: fmt.Sprintf("%s %s: %s: %s", app.cmd, app.subCmd, repo.Name, err),
}
return
}
Expand Down
23 changes: 3 additions & 20 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,17 @@ func (app *appEnv) parse(args []string) (string, bool) {
switch {
// This must precede all other checks.
case err != nil:
fmt.Fprintf(
os.Stderr,
"%s %s: %s\n%s",
app.cmd,
app.subCmd,
err,
app.usage,
)
fmt.Fprintf(os.Stderr, "%s %s: %s\n%s", app.cmd, app.subCmd, err, app.usage)
app.exitValue = exitFailure
case helpWanted:
fmt.Fprintf(
os.Stderr,
"%s: use 'help' not '-help' or '-h'\n%s",
app.cmd,
app.usage,
)
fmt.Fprintf(os.Stderr, "%s: use 'help' not '-help' or '-h'\n%s", app.cmd, app.usage)
app.exitValue = exitFailure
case configFile == "":
configFile = defaultConfig
configIsDefault = true
}
if len(cmdFlags.Args()) > 0 {
fmt.Fprintf(
os.Stderr,
"%s %s: no arguments accepted\n",
app.cmd,
app.subCmd,
)
fmt.Fprintf(os.Stderr, "%s %s: no arguments accepted\n", app.cmd, app.subCmd)
app.exitValue = exitFailure
}
return configFile, configIsDefault
Expand Down
16 changes: 2 additions & 14 deletions internal/cli/gitmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ func CmdGitmirror(args []string) int {
`, "`")
version := "v0.9.0"
if len(args) < 1 {
fmt.Fprintf(
os.Stderr,
"%s: required subcommand missing\n%s",
cmd,
usage,
)
fmt.Fprintf(os.Stderr, "%s: required subcommand missing\n%s", cmd, usage)
return exitFailure
}
app := newAppEnv(cmd, usage, version, args[0])
Expand All @@ -46,16 +41,9 @@ func CmdGitmirror(args []string) int {
case "version":
cmdVersion(app, args[1:])
case "help":
// TODO: write the help in Asciidoc?
cmdHelp(app, args[1:])
default:
fmt.Fprintf(
os.Stderr,
"%s: unrecognized subcommand: \"%s\"\n%s",
app.cmd,
app.subCmd,
app.usage,
)
fmt.Fprintf(os.Stderr, "%s: unrecognized subcommand: \"%s\"\n%s", app.cmd, app.subCmd, app.usage)
app.exitValue = exitFailure
}
return app.exitValue
Expand Down
21 changes: 3 additions & 18 deletions internal/cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,12 @@ func (app *appEnv) help(args []string) {
return
}
if len(args) < 1 {
fmt.Fprintf(
os.Stderr,
"%s help: no subcommand given\n%s",
app.cmd,
helpUsage,
)
fmt.Fprintf(os.Stderr, "%s help: no subcommand given\n%s", app.cmd, helpUsage)
app.exitValue = exitFailure
return
}
if len(args) > 1 {
fmt.Fprintf(
os.Stderr,
"%s help: too many arguments: %+v\n",
app.cmd,
args,
)
fmt.Fprintf(os.Stderr, "%s help: too many arguments: %+v\n", app.cmd, args)
fmt.Fprint(os.Stderr, helpUsage)
app.exitValue = exitFailure
return
Expand All @@ -40,12 +30,7 @@ func (app *appEnv) help(args []string) {
case "version":
fmt.Fprint(os.Stdout, versionUsage)
default:
fmt.Fprintf(
os.Stderr,
"%s help: unrecognized subcommand: \"%s\"\n",
app.cmd,
args[0],
)
fmt.Fprintf(os.Stderr, "%s help: unrecognized subcommand: \"%s\"\n", app.cmd, args[0])
fmt.Fprint(os.Stderr, helpUsage)
app.exitValue = exitFailure
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func (app *appEnv) getRepos(configFile string, configIsDefault bool) []Repo {
}
blob, err := os.ReadFile(configFile)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", app.cmd, err)
fmt.Fprintf(os.Stderr, "%s %s: %s\n", app.cmd, app.subCmd, err)
app.exitValue = exitFailure
return nil
}
repos := make([]Repo, 0, 20)
err = json.Unmarshal(blob, &repos)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", app.cmd, err)
fmt.Fprintf(os.Stderr, "%s %s: %s\n", app.cmd, app.subCmd, err)
app.exitValue = exitFailure
return nil
}
Expand Down
7 changes: 1 addition & 6 deletions internal/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ func (app *appEnv) showVersion(args []string) {
return
}
if len(args) != 0 {
fmt.Fprintf(
os.Stderr,
"%s version: no arguments accepted\n%s",
app.cmd,
versionUsage,
)
fmt.Fprintf(os.Stderr, "%s %s: no arguments accepted\n%s", app.cmd, app.subCmd, versionUsage)
app.exitValue = exitFailure
return
}
Expand Down

0 comments on commit 6aedc8e

Please sign in to comment.