-
Notifications
You must be signed in to change notification settings - Fork 4
/
kind.go
44 lines (37 loc) · 925 Bytes
/
kind.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
40
41
42
43
44
// Copyright © 2015-2016 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by the GPL-2 license described in the
// LICENSE file.
package cmd
const (
DontFork Kind = 1 << iota
Daemon
Hidden
CantPipe
)
func WhatKind(v Cmd) Kind {
if m, found := v.(kinder); found {
return m.Kind()
}
return 0
}
type kinder interface {
Kind() Kind
}
type Kind uint16
func (k Kind) IsDontFork() bool { return (k & DontFork) == DontFork }
func (k Kind) IsDaemon() bool { return (k & Daemon) == Daemon }
func (k Kind) IsHidden() bool { return (k & Hidden) == Hidden }
func (k Kind) IsInteractive() bool { return (k & (Daemon | Hidden)) == 0 }
func (k Kind) IsCantPipe() bool { return (k & CantPipe) == CantPipe }
func (k Kind) String() string {
s := "unknown"
switch k {
case DontFork:
s = "don't fork"
case Daemon:
s = "daemon"
case Hidden:
s = "hidden"
}
return s
}