-
Notifications
You must be signed in to change notification settings - Fork 19
/
service_config_locate.go
98 lines (79 loc) · 2.74 KB
/
service_config_locate.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
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"fmt"
"io"
"code.vegaprotocol.io/vega/cmd/vegawallet/commands/cli"
"code.vegaprotocol.io/vega/cmd/vegawallet/commands/flags"
"code.vegaprotocol.io/vega/cmd/vegawallet/commands/printer"
"code.vegaprotocol.io/vega/paths"
svcStoreV1 "code.vegaprotocol.io/vega/wallet/service/store/v1"
"github.com/spf13/cobra"
)
var (
locateServiceConfigLong = cli.LongDesc(`
Locate the wallet service configuration file.
`)
locateServiceConfigExample = cli.Examples(`
# Locate the wallet service configuration file
{{.Software}} service config locate
`)
)
type LocateServiceConfigsResponse struct {
Path string `json:"path"`
}
type LocateServiceConfigsHandler func() (*LocateServiceConfigsResponse, error)
func NewCmdLocateServiceConfig(w io.Writer, rf *RootFlags) *cobra.Command {
h := func() (*LocateServiceConfigsResponse, error) {
vegaPaths := paths.New(rf.Home)
svcConfig, err := svcStoreV1.InitialiseStore(vegaPaths)
if err != nil {
return nil, fmt.Errorf("couldn't initialise service store: %w", err)
}
return &LocateServiceConfigsResponse{
Path: svcConfig.GetServiceConfigsPath(),
}, nil
}
return BuildCmdLocateServiceConfigs(w, h, rf)
}
func BuildCmdLocateServiceConfigs(w io.Writer, handler LocateServiceConfigsHandler, rf *RootFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "locate",
Short: " Locate the wallet service configuration file",
Long: locateServiceConfigLong,
Example: locateServiceConfigExample,
RunE: func(_ *cobra.Command, _ []string) error {
resp, err := handler()
if err != nil {
return err
}
switch rf.Output {
case flags.InteractiveOutput:
PrintLocateServiceConfigsResponse(w, resp)
case flags.JSONOutput:
return printer.FprintJSON(w, resp)
}
return nil
},
}
return cmd
}
func PrintLocateServiceConfigsResponse(w io.Writer, resp *LocateServiceConfigsResponse) {
p := printer.NewInteractivePrinter(w)
str := p.String()
defer p.Print(str)
str.Text("The service configuration file is located at: ").SuccessText(resp.Path).NextLine()
}