-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
155 lines (127 loc) · 3.82 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"fmt"
"os"
surveyCore "github.com/AlecAivazis/survey/v2/core"
"github.com/logfire-sh/cli/pkg/cmd/factory"
"github.com/logfire-sh/cli/pkg/cmd/root"
"github.com/mgutz/ansi"
"github.com/spf13/cobra"
)
type SignupRequest struct {
Email string `json:"email"`
}
type SigninRequest struct {
AuthType int `json:"authType"`
Credential string `json:"credential"`
}
type OnboardRequest struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}
type SetPassword struct {
Password string `json:"password"`
}
type UserBody struct {
ProfileID string `json:"profileId"`
TeamID string `json:"teamId"`
Onboarded bool `json:"onboarded"`
Email string `json:"email"`
}
type BearerToken struct {
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
Exp string `json:"exp"`
Iat string `json:"iat"`
}
type Response struct {
IsSuccessful bool `json:"isSuccessful"`
Code int `json:"code"`
Email string `json:"email"`
UserBody UserBody `json:"userBody"`
BearerToken BearerToken `json:"bearerToken"`
Message []string `json:"message"`
}
type SigninPasswordRequest struct {
Email string `json:"email"`
AuthType int `json:"authType"`
Credential string `json:"credential"`
}
func main() {
cmdFactory := factory.New()
cmdCh := make(chan bool)
stderr := cmdFactory.IOStreams.ErrOut
rootCmd, err := root.NewCmdRoot(cmdFactory, cmdCh)
if err != nil {
fmt.Fprintf(stderr, "failed to create root command: %s\n", err)
return
}
if !cmdFactory.IOStreams.ColorEnabled() {
surveyCore.DisableColor = true
ansi.DisableColors(true)
} else {
// override survey's poor choice of color
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
switch style {
case "white":
return ansi.ColorCode("default")
default:
return ansi.ColorCode(style)
}
}
}
expandedArgs := []string{}
if len(os.Args) > 0 {
expandedArgs = os.Args[1:]
}
// translate `gh help <command>` to `gh <command> --help` for extensions.
if len(expandedArgs) >= 2 && expandedArgs[0] == "help" && isExtensionCommand(rootCmd, expandedArgs[1:]) {
expandedArgs = expandedArgs[1:]
expandedArgs = append(expandedArgs, "--help")
}
rootCmd.SetArgs(expandedArgs)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(stderr, "failed to run application: %s\n", err)
}
// rootCmd := &cobra.Command{
// Use: "logfire <command> <subcommand> [flags]",
// Short: "Logfire CLI",
// Long: `Work seamlessly with Logfire.sh log management system from the command line.`,
// Example: heredoc.Doc(`
// $ logfire auth login
// $ logfire livetail show
// `),
// // PersistentPreRun: func(cmd *cobra.Command, args []string) {
// // // require that the user is authenticated before running most commands
// // if cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
// // fmt.Fprint(io.ErrOut, authHelp())
// // }
// // },
// }
// rootCmd.AddGroup(&cobra.Group{
// ID: "core",
// Title: "Core commands",
// })
// sourceCmd := &cobra.Command{
// Use: "sources [list/create/delete] [config_file]",
// Short: "manage the sources",
// Args: cobra.ExactArgs(2),
// Run: sourceManage,
// }
// livetailCmd := &cobra.Command{
// Use: "livetail ",
// Short: "display the livetail",
// Args: cobra.ExactArgs(1),
// Run: livetailShow,
// }
// rootCmd.AddCommand(auth.NewCmdAuth())
// rootCmd.AddCommand(sourceCmd, livetailCmd)
// if err := rootCmd.Execute(); err != nil {
// fmt.Println(err)
// }
}
// isExtensionCommand returns true if args resolve to an extension command.
func isExtensionCommand(rootCmd *cobra.Command, args []string) bool {
c, _, err := rootCmd.Find(args)
return err == nil && c != nil && c.GroupID == "extension"
}