-
Notifications
You must be signed in to change notification settings - Fork 28
/
flags.go
102 lines (92 loc) · 2.48 KB
/
flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package clienv
import (
"fmt"
"os"
"path/filepath"
"github.com/go-git/go-git/v5"
"github.com/urfave/cli/v2"
)
const (
flagDomain = "domain"
flagBranch = "branch"
flagProjectName = "project-name"
flagRootFolder = "root-folder"
flagDataFolder = "data-folder"
flagNhostFolder = "nhost-folder"
flagDotNhostFolder = "dot-nhost-folder"
)
func getGitBranchName() string {
repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{
DetectDotGit: true,
EnableDotGitCommonDir: false,
})
if err != nil {
return "nogit"
}
head, err := repo.Head()
if err != nil {
return "nogit"
}
return head.Name().Short()
}
func Flags() ([]cli.Flag, error) { //nolint:funlen
fullWorkingDir, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("failed to get working directory: %w", err)
}
branch := getGitBranchName()
workingDir := "."
dotNhostFolder := filepath.Join(workingDir, ".nhost")
dataFolder := filepath.Join(dotNhostFolder, "data", branch)
nhostFolder := filepath.Join(workingDir, "nhost")
return []cli.Flag{
&cli.StringFlag{ //nolint:exhaustruct
Name: flagDomain,
Usage: "Nhost domain",
EnvVars: []string{"NHOST_DOMAIN"},
Value: "nhost.run",
Hidden: true,
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagBranch,
Usage: "Git branch name",
EnvVars: []string{"BRANCH"},
Value: branch,
Hidden: true,
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagRootFolder,
Usage: "Root folder of project\n\t",
EnvVars: []string{"NHOST_ROOT_FOLDER"},
Value: workingDir,
Category: "Project structure",
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagDotNhostFolder,
Usage: "Path to .nhost folder\n\t",
EnvVars: []string{"NHOST_DOT_NHOST_FOLDER"},
Value: dotNhostFolder,
Category: "Project structure",
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagDataFolder,
Usage: "Data folder to persist data\n\t",
EnvVars: []string{"NHOST_DATA_FOLDER"},
Value: dataFolder,
Category: "Project structure",
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagNhostFolder,
Usage: "Path to nhost folder\n\t",
EnvVars: []string{"NHOST_NHOST_FOLDER"},
Value: nhostFolder,
Category: "Project structure",
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagProjectName,
Usage: "Project name",
Value: filepath.Base(fullWorkingDir),
EnvVars: []string{"NHOST_PROJECT_NAME"},
},
}, nil
}