-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser.go
More file actions
33 lines (29 loc) · 617 Bytes
/
user.go
File metadata and controls
33 lines (29 loc) · 617 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
// Package main contains the logic for the "user" command
package main
import (
"errors"
"log"
"os/exec"
"strings"
"github.com/oalders/is/command"
"github.com/oalders/is/types"
)
// Run "is user ...".
func (r *UserCmd) Run(ctx *types.Context) error {
if ctx.Debug {
log.Printf("Running \"sudo -n true\"\n")
}
cmd := exec.CommandContext(ctx.Context, "sudo", "-n", "true")
output, err := command.Output(cmd, "stderr")
if err != nil {
if !errors.Is(err, exec.ErrNotFound) {
return err
}
return nil
}
if strings.Contains(output, "password") {
return nil
}
ctx.Success = true
return nil
}