forked from fydrah/loginapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
80 lines (76 loc) · 2.17 KB
/
cli.go
File metadata and controls
80 lines (76 loc) · 2.17 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
// Copyright 2018 fydrah
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Some code comes from @ericchiang (Dex - CoreOS)
package main
import (
"fmt"
"github.com/prometheus/common/version"
"github.com/urfave/cli"
)
// NewCli configure loginapp CLI
func NewCli() *cli.App {
app := cli.NewApp()
cli.AppHelpTemplate = `
NAME:
{{.Name}} - {{.UsageText}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}
USAGE:
{{.HelpName}}{{if .VisibleFlags}} [global options]{{end}}{{if .Commands}} command [command options]{{end}}
{{if .Commands}}
COMMANDS:
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
GLOBAL OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
app.UsageText = "Web application for Kubernetes CLI configuration with OIDC"
app.Version = version.Print("loginapp")
app.Authors = []cli.Author{
{
Name: "fydrah",
Email: "flav.hardy@gmail.com",
},
}
app.Commands = []cli.Command{
{
Name: "serve",
Usage: "Run loginapp application",
SkipFlagParsing: true,
ArgsUsage: "[configuration file]",
Before: func(c *cli.Context) error {
return nil
},
Action: func(c *cli.Context) error {
if len(c.Args()) == 0 {
if err := cli.ShowCommandHelp(c, c.Command.Name); err != nil {
return fmt.Errorf("Error while rendering command help: %v", err)
}
return fmt.Errorf("Missing argument")
}
s := &Server{}
if err := s.config.Init(c.Args().First()); err != nil {
return err
}
if err := s.Run(); err != nil {
return err
}
return nil
},
},
}
return app
}