Skip to content

Commit 9ea9d3d

Browse files
authored
refactor: Hello message (#47)
1 parent b435489 commit 9ea9d3d

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

cmd/aoc-cli/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/briandowns/spinner"
1414
"github.com/manifoldco/promptui"
1515
log "github.com/obalunenko/logger"
16-
"github.com/obalunenko/version"
1716
"github.com/urfave/cli"
1817

1918
"github.com/obalunenko/advent-of-code/internal/puzzles"
@@ -41,13 +40,13 @@ func main() {
4140
"answers for input on site."
4241
app.Usage = `a command line tool for get solution for Advent of Code puzzles`
4342
app.Author = "Oleg Balunenko"
44-
app.Version = version.GetVersion()
43+
app.Version = printVersion(ctx)
4544
app.Email = "[email protected]"
4645

4746
app.Flags = flags()
4847

4948
app.Action = menu(ctx)
50-
app.Before = printVersion
49+
app.Before = printHeader
5150
app.After = onExit
5251

5352
if err := app.Run(os.Args); err != nil {

cmd/aoc-cli/version.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,42 @@
22
package main
33

44
import (
5+
"context"
56
"fmt"
67
"os"
8+
"strings"
79
"text/tabwriter"
810

11+
log "github.com/obalunenko/logger"
912
"github.com/obalunenko/version"
1013
"github.com/urfave/cli"
1114
)
1215

13-
func printVersion(_ *cli.Context) error {
16+
func printHeader(_ *cli.Context) error {
1417
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
1518

19+
_, err := fmt.Fprintf(w, `
20+
21+
█████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗████████╗ ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗
22+
██╔══██╗██╔══██╗██║ ██║██╔════╝████╗ ██║╚══██╔══╝ ██╔═══██╗██╔════╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝
23+
███████║██║ ██║██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ██║█████╗ ██║ ██║ ██║██║ ██║█████╗
24+
██╔══██║██║ ██║╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██╔══╝ ██║ ██║ ██║██║ ██║██╔══╝
25+
██║ ██║██████╔╝ ╚████╔╝ ███████╗██║ ╚████║ ██║ ╚██████╔╝██║ ╚██████╗╚██████╔╝██████╔╝███████╗
26+
╚═╝ ╚═╝╚═════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
27+
28+
`)
29+
if err != nil {
30+
return fmt.Errorf("print version: %w", err)
31+
}
32+
33+
return nil
34+
}
35+
36+
func printVersion(ctx context.Context) string {
37+
var buf strings.Builder
38+
39+
w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', tabwriter.TabIndent)
40+
1641
_, err := fmt.Fprintf(w, `
1742
| app_name: %s |
1843
| version: %s |
@@ -34,8 +59,12 @@ func printVersion(_ *cli.Context) error {
3459
version.GetBuildDate(),
3560
version.GetGoVersion())
3661
if err != nil {
37-
return fmt.Errorf("print version: %w", err)
62+
log.WithError(ctx, err).Fatal("fprintf")
3863
}
3964

40-
return nil
65+
if err := w.Flush(); err != nil {
66+
log.WithError(ctx, err).Fatal("flush")
67+
}
68+
69+
return buf.String()
4170
}

0 commit comments

Comments
 (0)