-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_show.go
More file actions
42 lines (34 loc) · 888 Bytes
/
Copy pathcommand_show.go
File metadata and controls
42 lines (34 loc) · 888 Bytes
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
package main
import (
"fmt"
"path/filepath"
"strings"
"github.com/sirkon/errors"
"github.com/sirkon/portalctl/internal/portallog"
)
// CommandShow реализация команды show.
type CommandShow struct {
Name string `arg:"" required:"true" help:"Portal name."`
}
// Run запуск команды.
func (d CommandShow) Run(ctx *RunContext) error {
pos := strings.IndexByte(d.Name, '/')
if pos == -1 {
path, err := portallog.LogShowPortalPath(ctx.opLogFile, string(d.Name))
if err != nil {
return errors.Wrapf(err, "look for portal %q", d.Name)
}
fmt.Println(path)
return nil
}
if pos == 0 {
return nil
}
path, err := portallog.LogShowPortalPath(ctx.opLogFile, d.Name[:pos])
if err != nil {
return errors.Wrapf(err, "look for portal of %q path", d.Name)
}
suffix := d.Name[pos+1:]
fmt.Println(filepath.Join(path, suffix))
return nil
}