-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
95 lines (78 loc) · 2.26 KB
/
main.go
File metadata and controls
95 lines (78 loc) · 2.26 KB
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
package main
import (
"context"
"net/http"
"github.com/jay7x/pct/internal/pkg/pct_config_processor"
"github.com/jay7x/pct/pkg/exec_runner"
cmd_build "github.com/jay7x/pct/cmd/build"
"github.com/jay7x/pct/cmd/completion"
"github.com/jay7x/pct/cmd/explain"
cmd_install "github.com/jay7x/pct/cmd/install"
"github.com/jay7x/pct/cmd/new"
"github.com/jay7x/pct/cmd/root"
appver "github.com/jay7x/pct/cmd/version"
"github.com/jay7x/pct/pkg/build"
"github.com/jay7x/pct/pkg/gzip"
"github.com/jay7x/pct/pkg/install"
"github.com/jay7x/pct/pkg/tar"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
ctx := context.Background()
var rootCmd = root.CreateRootCommand()
var verCmd = appver.CreateVersionCommand(version, date, commit)
v := appver.Format(version, date, commit)
rootCmd.Version = v
rootCmd.SetVersionTemplate(v)
rootCmd.AddCommand(verCmd)
rootCmd.AddCommand(completion.CreateCompletionCommand())
// afero setup
fs := afero.NewOsFs()
afs := afero.Afero{Fs: fs}
iofs := afero.IOFS{Fs: fs}
// build
buildCmd := cmd_build.BuildCommand{
ProjectType: "template",
Builder: &build.Builder{
Tar: &tar.Tar{AFS: &afero.Afero{Fs: fs}},
Gzip: &gzip.Gzip{AFS: &afero.Afero{Fs: fs}},
AFS: &afero.Afero{Fs: fs},
ConfigProcessor: &pct_config_processor.PctConfigProcessor{AFS: &afero.Afero{Fs: fs}},
ConfigFile: "pct-config.yml",
},
}
rootCmd.AddCommand(buildCmd.CreateCommand())
// install
installCmd := cmd_install.InstallCommand{
PctInstaller: &install.Installer{
Tar: &tar.Tar{AFS: &afs},
Gunzip: &gzip.Gunzip{AFS: &afs},
AFS: &afs,
IOFS: &iofs,
HTTPClient: &http.Client{},
Exec: &exec_runner.Exec{},
ConfigProcessor: &pct_config_processor.PctConfigProcessor{
AFS: &afs,
},
ConfigFileName: "pct-config.yml",
},
AFS: &afs,
}
rootCmd.AddCommand(installCmd.CreateCommand())
// new
rootCmd.AddCommand(new.CreateCommand())
// explain
rootCmd.AddCommand(explain.CreateCommand())
// initialize
cobra.OnInitialize(root.InitLogger, root.InitConfig)
// execute called command
err := rootCmd.ExecuteContext(ctx)
// Handle exiting with/out errors.
cobra.CheckErr(err)
}