-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathauth_status.go
More file actions
32 lines (26 loc) · 646 Bytes
/
auth_status.go
File metadata and controls
32 lines (26 loc) · 646 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
package main
import (
"errors"
"fmt"
"go.abhg.dev/gs/internal/forge"
"go.abhg.dev/gs/internal/secret"
"go.abhg.dev/gs/internal/silog"
)
type authStatusCmd struct{}
func (*authStatusCmd) Help() string {
return `Exits with a non-zero code if not logged in.`
}
func (cmd *authStatusCmd) Run(
stash secret.Stash,
log *silog.Logger,
f forge.Forge,
) error {
if _, err := f.LoadAuthenticationToken(stash); err != nil {
if errors.Is(err, secret.ErrNotFound) {
return fmt.Errorf("%s: not logged in", f.ID())
}
return fmt.Errorf("load authentication token: %w", err)
}
log.Infof("%s: currently logged in", f.ID())
return nil
}