Line data Source code
1 : package cmd
2 :
3 : import (
4 : "context"
5 : "errors"
6 : "fmt"
7 :
8 : "github.com/kijimaD/ruins/internal/consts"
9 : "github.com/urfave/cli/v3"
10 : )
11 :
12 : const splash = `───────────────────────────────────────────────────────
13 : ██████ ██ ██ ██ ███ ██ ███████
14 : ██ ██ ██ ██ ██ ████ ██ ██
15 : ██████ ██ ██ ██ ██ ██ ██ ███████
16 : ██ ██ ██ ██ ██ ██ ██ ██ ██
17 : ██ ██ ██████ ██ ██ ████ ███████
18 : ───────────────────────────────────────────────────────
19 : `
20 :
21 : // NewMainApp は新しいメインアプリケーションを作成する
22 : func NewMainApp() *cli.Command {
23 1 : app := &cli.Command{
24 1 : Name: "ruins",
25 1 : Usage: "ruins [subcommand] [args]",
26 1 : Description: splash + "\nThis is Roguelike!",
27 1 : Version: consts.AppVersion,
28 1 : Commands: []*cli.Command{
29 1 : CmdPlay,
30 1 : CmdBalanceReport,
31 1 : CmdGenReadme,
32 1 : CmdGenComponents,
33 1 : CmdDesignDoc,
34 1 : CmdBenchgate,
35 1 : CmdFmtRaw,
36 1 : CmdCutSprite,
37 1 : CmdLayoutPNG,
38 1 : },
39 1 : }
40 :
41 1 : return app
42 1 : }
43 :
44 : // errCommandExecution はサブコマンドの実行が失敗したときに返す
45 : var errCommandExecution = errors.New("command execution failed")
46 :
47 : // RunMainApp はメインアプリケーションを実行する
48 : func RunMainApp(app *cli.Command, args ...string) error {
49 1 : err := app.Run(context.Background(), args)
50 1 : if err != nil {
51 1 : return fmt.Errorf("%w: %w", errCommandExecution, err)
52 1 : }
53 :
54 1 : return nil
55 : }
|