-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
37 lines (30 loc) · 880 Bytes
/
profile.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
package main
import (
"flag"
"maps"
"github.com/joomcode/errorx"
)
var (
ErrProfileNamespace = errorx.NewNamespace("profile")
ErrNoProfileName = errorx.NewType(ErrProfileNamespace, "NoProfileName")
ErrProfileNotFound = errorx.NewType(ErrProfileNamespace, "ProfileNotFound")
)
func ReadProfile(printer Printer) (*ProfileParams, error) {
app, err := ReadParams()
if err != nil {
return nil, err
}
profileName := flag.String("p", "", "Profile to use")
flag.Parse()
if *profileName == "" {
return nil, ErrNoProfileName.New("Profile name is not pass. Use -p flag")
}
profile, exists := app.Profiles[*profileName]
if !exists {
return nil, ErrProfileNotFound.New(
"no profile found %v; known profiles are: %v", *profileName, maps.Keys(app.Profiles),
)
}
printer.Println("Добро пожаловать, %v!", *profileName)
return &profile, nil
}