summarylogtreecommitdiffstats
path: root/trakts.zsh
blob: 038b11eae0693d80480376e68b7137e6866e0e5d (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#compdef trakts
#
# Zsh auto complete function for trakts
#

# Section: trakts autostart
_trakts_autostart_actions()
{
    local actions
    actions=(
        "enable:Install and enable the autostart service"
        "disable:Disable the autostart service"
    )
    _describe 'actions' actions
}
# command: trakts autostart
_trakts_autostart()
{
    _arguments '1:action:_trakts_autostart_actions'
}
# Section: trakts backlog
_trakts_backlog_actions()
{
    local actions
    actions=(
        "clear:Try to sync the backlog with trakt servers"
        "list:List the files in backlog"
    )
    _describe 'actions' actions
}
# command: trakts backlog
_trakts_backlog()
{
    _arguments '1:action:_trakts_backlog_actions'
}

# Section: trakts config
_trakts_config_actions()
{
    local actions
    actions=(
        'list:List configuration settings'
        'set:Set the value for a config parameter'
        'unset:Reset a config value to its default'
    )
    _describe 'actions' actions
}
# command: trakts config
_trakts_config()
{
    local args line
    args=(
        '1:action:_trakts_config_actions'
        '*::arg:->args'
    )
    _arguments -s "${args[@]}"
    case $line[1] in
        (list)
            _arguments '--all[Include default values]'
        ;;
        (set)
            _trakts_config_set "$@"
        ;;
        (unset)
            _trakts_config_list "$@"
        ;;
    esac
}
# command: trakts config set
_trakts_config_set()
{
    local args
    args=(
        '1:key:_trakts_config_list'
        '2:value:'
        '--add[Append to list instead of overwriting]'
    )
    _arguments -s "${args[@]}"
}
# command: trakts config list
_trakts_config_list()
{
    local keys
    keys=(
        $(trakts config list --all|cut -d\  -f1)
    )
    _describe 'keys' keys
}

# Section: trakts init
_trakts_init_actions()
{
    true
}
# command: trakts init
_trakts_init()
{
    _arguments '1:action:_trakts_init_actions'
}
# no subcommand or options provided

# Section: trakts log
_trakts_log_actions()
{
    local actions
    actions=(
        'open:Open Latest log.'
        'path:Prints the location of the log file'
    )
    _describe 'actions' actions
}
# command: trakts log
_trakts_log()
{
    _arguments '1:action:_trakts_log_actions'
}

# Section: trakts plex
# command: trakts plex
_trakts_plex()
{
    _arguments -s '-f[Force run the flow]'
}

# Section: trakts run
# command: trakts run
_trakts_run()
{
    true
}

# Section: trakts start
# command: trakts start
_trakts_start()
{
    _arguments -s {-r,--restart}'[Restart the service]'
}

# Section: trakts status
# command: trakts status
_trakts_status()
{
    true
}

# Section: trakts stop
# command: trakts stop
_trakts_stop()
{
    true
}

# Section: trakts whitelist
_trakts_whitelist_actions()
{
    local actions
    actions=(
        'add:Add folder(s) to whitelist'
        'remove:Remove folder(s) from whitelist'
        'show:Show the current whitelist'
        'test:Check whether the given file/folder is whitelisted'
    )
    _describe 'actions' actions
}
# command: trakts whitelist
_trakts_whitelist()
{
    local line state
    _arguments '1:action:_trakts_whitelist_actions' '::path:->path'
    case $line[1] in
        (add)
            _path_files -/
        ;;
        (test)
            _path_files
        ;;
        (*) true;;
    esac
}

# Section: trakts
_trakts_actions()
{
    local state actions
    actions=(
        "auth:Runs the authetication flow for trakt.tv"
        "autostart:Controls the autostart behaviour of the scrobbler"
        "backlog:Manage the not-yet-synced backlog of watched media"
        "config:Edit the scrobbler config settings"
        "help:Display the manual of a command"
        "init:Run the initial setup of the scrobble"
        "log:Access the log file"
        "plex:Run the authetication flow for plex media server"
        "run:Run the scrobbler in the foreground"
        "start:Start the trakt-scrobbler service"
        "status:Show the status trakt-scrobbler service"
        "stop:Stop the trakt-scrobbler service"
        "whitelist:Add the given folder(s) to whitelist"
    )
    _describe 'actions' actions
}
# command: trakts
local line args
args=(
    "1:actions:_trakts_actions"
    {-h,--help}"[Display help message]"
    {-q,--quiet}"[Do not output any message]"
    {-v,--verbose}"[Increase the verbosity of messages]"
    {-V,--version}"[Display this application version]"
    {-n,--no-interaction}"[Do not ask any interactive question]"
    "--ansi[Force ANSI output]"
    "--no-ansi[Disable ANSI output]"
    "*::arg:->args"
)
_arguments -s "${args[@]}"
case $line[1] in
    (help)
        case $CURRENT in
            (2)
                _trakts_actions "$@"
            ;;
            (3)
                if [ -n "$functions[_trakts_$line[2]_actions]" ];then
                    _trakts_$line[2]_actions "$@"
                fi
            ;;
            (4)
                if [ -n "$functions[_trakts_$line[2]_$line[3]_actions]" ];then
                    _trakts_$line[2]_$line[3]_actions "$@"
                fi
            ;;
            (5)
                if [ -n "$functions[_trakts_$line[2]_$line[3]_$line[4]_actions]" ];then
                    _trakts_$line[2]_$line[3]_$line[4]_actions "$@"
                fi
            ;;
            (6)
                if [ -n "$functions[_trakts_$line[2]_$line[3]_$line[4]_$line[5]_actions]" ];then
                    _trakts_$line[2]_$line[3]_$line[4]_$line[5]_actions "$@"
                fi
            ;;
        esac
    ;;
    (auth)
        _arguments '-f[Force run the flow]'
    ;;
    (*)
        if [ -n "$functions[_trakts_$line[1]]" ] ;then
            _trakts_$line[1] "$@"
        fi
    ;;
esac