-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
116 lines (95 loc) · 3.53 KB
/
main.go
File metadata and controls
116 lines (95 loc) · 3.53 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"os"
"path/filepath"
"slices"
"time"
"github.com/SoureCode/kyx/commands"
"github.com/SoureCode/kyx/project"
"github.com/SoureCode/kyx/shell"
"github.com/SoureCode/kyx/tools"
"github.com/pkg/errors"
"github.com/symfony-cli/console"
"github.com/symfony-cli/terminal"
)
var (
// version is overridden at linking time
version = "0.0.1"
// channel is overridden at linking time
channel = "dev"
// overridden at linking time
buildDate = time.Now().Format(time.RFC3339)
toolsMapping = tools.Mapping{
"phpstan": "https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar",
"php-cs-fixer": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar",
"infection": "https://github.com/infection/infection/releases/latest/download/infection.phar",
"composer-require-checker": "https://github.com/maglnet/ComposerRequireChecker/releases/latest/download/composer-require-checker.phar",
"composer-normalize": "https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar",
"composer-unused": "https://github.com/composer-unused/composer-unused/releases/latest/download/composer-unused.phar",
}
)
func main() {
if project.HasProject() {
p := project.GetProject()
logger := shell.GetLogger()
logger.AddHandler(shell.NewFileLogHandler(filepath.Join(p.GetDirectory(), "var", "log", "kyx.log")))
}
cmds := append(commands.GetCommands(), tools.GetCommands(toolsMapping)...)
cmds = append(cmds, tools.CreateCommand("test"))
toolNames := tools.GetNames(toolsMapping)
args := os.Args
if len(args) >= 2 && slices.Contains(toolNames, args[1]) {
cmd := tools.NewToolCommand(args[1], toolsMapping, args[2:]...)
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error executing command for tool %s: %v\n", args[1], err)
os.Exit(cmd.ExitCode())
}
os.Exit(0)
}
if len(args) >= 2 && args[1] == "test" {
p := project.GetProject()
pd := p.GetDirectory()
if p.HasDevDependency("symfony/phpunit-bridge") {
cmd := shell.NewPHPCommand(append([]string{filepath.Join(pd, "vendor", "bin", "simple-phpunit")}, args[2:]...)...).WithPassthrough()
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error executing simple-phpunit: %v\n", err)
os.Exit(cmd.ExitCode())
}
os.Exit(0)
} else if p.HasDevDependency("phpunit/phpunit") {
cmd := shell.NewPHPCommand(append([]string{filepath.Join(pd, "vendor", "bin", "phpunit")}, args[2:]...)...).WithPassthrough()
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error executing phpunit: %v\n", err)
os.Exit(cmd.ExitCode())
}
os.Exit(0)
}
// very informative and helpful error message
fmt.Fprintf(os.Stderr, "No test runner found. Please install either symfony/phpunit-bridge or phpunit/phpunit as a dev dependency.\n")
os.Exit(1)
}
app := &console.Application{
Name: "kyx",
Usage: "kyx [command] [options]",
Copyright: fmt.Sprintf("(c) 2025-%d Jason Schilling", time.Now().Year()),
Commands: cmds,
Before: func(ctx *console.Context) error {
shell.GetConsoleLogHandler().SetLogLevel(terminal.GetLogLevel())
return nil
},
Action: func(ctx *console.Context) error {
if ctx.Args().Len() == 0 {
return commands.WelcomeAction(ctx)
}
return console.ShowAppHelpAction(ctx)
},
Version: version,
Channel: channel,
BuildDate: buildDate,
}
err := app.Run(args)
if err != nil {
panic(errors.Wrap(err, "could not run application"))
}
}