-
Notifications
You must be signed in to change notification settings - Fork 30
/
spawn.go
39 lines (30 loc) · 809 Bytes
/
spawn.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
package main
import (
"fmt"
"time"
"github.com/miquella/ask"
"github.com/miquella/vaulted/lib"
)
type Spawn struct {
SessionOptions
Command []string
DisplayStatus bool
}
func (s *Spawn) Run(store vaulted.Store) error {
session, err := GetSessionWithOptions(store, &s.SessionOptions)
if err != nil {
return err
}
timeRemaining := session.Expiration.Sub(time.Now())
timeRemaining = time.Second * time.Duration(timeRemaining.Seconds())
if s.DisplayStatus {
ask.Print(fmt.Sprintf("%s — expires: %s (%s remaining)\n", session.Name, session.Expiration.Format("2 Jan 2006 15:04 MST"), timeRemaining))
}
code, err := session.Spawn(s.Command)
if err != nil {
return ErrorWithExitCode{err, 2}
} else if *code != 0 {
return ErrorWithExitCode{ErrNoError, *code}
}
return nil
}