-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
81 lines (72 loc) · 2.09 KB
/
main.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
// Package main contains the entry point of the uipath command line interface.
//
// It only initializes the different packages and delegates the actual work.
package main
import (
"embed"
"fmt"
"os"
"runtime"
"github.com/UiPath/uipathcli/auth"
"github.com/UiPath/uipathcli/cache"
"github.com/UiPath/uipathcli/commandline"
"github.com/UiPath/uipathcli/config"
"github.com/UiPath/uipathcli/executor"
"github.com/UiPath/uipathcli/parser"
"github.com/UiPath/uipathcli/plugin"
plugin_digitizer "github.com/UiPath/uipathcli/plugin/digitizer"
plugin_orchestrator "github.com/UiPath/uipathcli/plugin/orchestrator"
"github.com/UiPath/uipathcli/utils"
)
//go:embed definitions/*.yaml
var embedded embed.FS
func authenticators() []auth.Authenticator {
return []auth.Authenticator{
auth.NewPatAuthenticator(),
auth.NewOAuthAuthenticator(cache.NewFileCache(), auth.NewExecBrowserLauncher()),
auth.NewBearerAuthenticator(cache.NewFileCache()),
}
}
func colorsSupported() bool {
_, noColorSet := os.LookupEnv("NO_COLOR")
term, _ := os.LookupEnv("TERM")
omitColors := noColorSet || term == "dumb" || runtime.GOOS == "windows"
return !omitColors
}
func stdIn() utils.Stream {
return utils.NewReaderStream(parser.RawBodyParameterName, os.Stdin)
}
func main() {
configProvider := config.NewConfigProvider(
config.NewConfigFileStore(os.Getenv("UIPATH_CONFIGURATION_PATH")),
)
err := configProvider.Load()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(131)
}
authenticators := authenticators()
cli := commandline.NewCli(
os.Stdin,
os.Stdout,
os.Stderr,
colorsSupported(),
*commandline.NewDefinitionProvider(
commandline.NewDefinitionFileStore(os.Getenv("UIPATH_DEFINITIONS_PATH"), embedded),
parser.NewOpenApiParser(),
[]plugin.CommandPlugin{
plugin_digitizer.DigitizeCommand{},
plugin_orchestrator.UploadCommand{},
plugin_orchestrator.DownloadCommand{},
},
),
*configProvider,
executor.NewHttpExecutor(authenticators),
executor.NewPluginExecutor(authenticators),
)
input := stdIn()
err = cli.Run(os.Args, input)
if err != nil {
os.Exit(1)
}
}