CommandLineToolkit

Форк
0
111 строк · 2.3 Кб
1
import Foundation
2
import Signals
3

4
// swiftlint:disable sync
5
public enum Signal: Hashable, CustomStringConvertible, RawRepresentable {
6
    case hup
7
    case int
8
    case quit
9
    case abrt
10
    case kill
11
    case alrm
12
    case term
13
    case pipe
14
    case user(Int32)
15

16
    public init(rawValue: Int32) {
17
        self = switch rawValue {
18
        case SIGHUP:
19
            .hup
20
        case SIGINT:
21
            .int
22
        case SIGQUIT:
23
            .quit
24
        case SIGABRT:
25
            .abrt
26
        case SIGKILL:
27
            .kill
28
        case SIGALRM:
29
            .alrm
30
        case SIGTERM:
31
            .term
32
        case SIGPIPE:
33
            .pipe
34
        default:
35
            .user(rawValue)
36
        }
37
    }
38

39
    public var description: String {
40
        switch self {
41
        case .hup:
42
            return "SIGHUP"
43
        case .int:
44
            return "SIGINT"
45
        case .quit:
46
            return "SIGQUIT"
47
        case .abrt:
48
            return "SIGABRT"
49
        case .kill:
50
            return "SIGKILL"
51
        case .alrm:
52
            return "SIGALRM"
53
        case .term:
54
            return "SIGTERM"
55
        case .pipe:
56
            return "SIGPIPE"
57
        case .user(let value):
58
            return "SIGUSR(\(value))"
59
        }
60
    }
61
    
62
    public var intValue: Int32 {
63
        switch self {
64
        case .hup:
65
            return SIGHUP
66
        case .int:
67
            return SIGINT
68
        case .quit:
69
            return SIGQUIT
70
        case .abrt:
71
            return SIGABRT
72
        case .kill:
73
            return SIGKILL
74
        case .alrm:
75
            return SIGALRM
76
        case .term:
77
            return SIGTERM
78
        case .pipe:
79
            return SIGPIPE
80
        case .user(let value):
81
            return Int32(value)
82
        }
83
    }
84

85
    public var rawValue: Int32 {
86
        intValue
87
    }
88

89
    var blueSignal: Signals.Signal {
90
        switch self {
91
        case .hup:
92
            return .hup
93
        case .int:
94
            return .int
95
        case .quit:
96
            return .quit
97
        case .abrt:
98
            return .abrt
99
        case .kill:
100
            return .kill
101
        case .alrm:
102
            return .alrm
103
        case .term:
104
            return .term
105
        case .pipe:
106
            return .pipe
107
        case .user(let value):
108
            return .user(Int(value))
109
        }
110
    }
111
}
112

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.