-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_here.go
More file actions
37 lines (29 loc) · 846 Bytes
/
Copy pathcommand_here.go
File metadata and controls
37 lines (29 loc) · 846 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
package main
import (
"os"
"github.com/sirkon/errors"
"github.com/sirkon/portalctl/internal/portallog"
)
// CommandHere реализация команды here.
type CommandHere struct {
Name PortalName `arg:"" required:"true" help:"Portal name."`
}
// Run запуск команды.
func (d CommandHere) Run(ctx *RunContext) error {
data, err := portallog.LogRead(ctx.opLogFile)
if err != nil {
return errors.Wrap(err, "read op log data")
}
if _, ok := data[string(d.Name)]; ok {
return errors.Wrapf(err, "cannot overwrite existing portal %q", d.Name)
}
curdir, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "get current directory path")
}
oplog := portallog.NewLog(ctx.opLogFile)
if err := oplog.AddPortal(string(d.Name), curdir); err != nil {
return errors.Wrap(err, "store data")
}
return nil
}