OPCompletion.ps1

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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
function opCompletion {
    param($wordToComplete ,$commandAst)

    Set-Alias nct -Value New-CommandTree

    $commandTree = & {
        nct add "Add access for users or groups to groups or vaults." {
            nct group "Grant a group access to a vault." {
                nct '<GroupName>' "Name of the group"
                nct '<ValutName>' "Name of the Vault"
                nct --help "get help with add group"
            }

            nct user "Grant a user access to a vault or group." {
                nct '<GroupName>' "Name of the group"
                nct '<ValutName>' "Name of the Vault"
                nct --role "get help with add group"
                nct --help "get help with add group"
            }

            nct --help " get help with add"
        }

        nct confirm "Confirm a user." {
            nct --all "Confirm all outstanding invited users."
            nct --help " get help with add user"
        }

        nct create "Create an object." {
            nct document "Create a document." {
                nct '<FileName>' "Name of the file"
                nct --tags  "<tags> is a comma-separated list of tags to be added to the document."
                nct --title "The <title> of corresponding item."
                nct --vault "The <vault> to save the document into. Specify <vault> by UUID or name. If not specified, the document is stored in the user's personal vault."
                nct --help "get help with create document"
            }

            nct group "Create a group." {
                nct '<GroupName>' "Name of the group"
                nct --description "Set the new group's description"
                nct --help "get help with create group"
            }

            nct item  "Create a new item." {
                nct '<Category>' "Name the category"
                nct --generate-password "give the item a randomly generated password"
                nct --tags "<tags> is a comma separated list of tags to be added to the item."
                nct --title "The <title> of corresponding item."
                nct --url "The <url> that shouls be associated with this item."
                nct --vault "The <vault> to save the item into. Specify <vault> by UUID or name. If not specified the item is stored in the user's personal vault."
                nct --help "get help with create item"
            }

            nct user  "Create a new user." {
                nct '<Email_address>' "Email address of the new user"
                nct '<Name>' "Name of the new user"
                nct --language "Set the user's account <language> (default `"en`")"
                nct --help "get help with create user"
            }

            nct vault "Create a new vault." {
                nct '<Name>' "Name of the vault"
                nct --allow-admins-to-manage "<true|false> Allows or disallows admins to manage this vault. If not specified, the default policy of the server is applied."
                nct --description "A description for the vault."
                nct --help "get help with create vault"
            }

            nct --help "get help with create"
        }

        nct delete "Remove an object." {
            nct document "Move a document to the Trash." {
                nct '<Document>' "Name of the document you want to delete"
                nct --vault "Specify the <vault> to delete the document from. If not specified the document is searched for in all vaults."
                nct --help "get help with delete document"
            }

            nct group "Remove a group." {
                nct '<Group>' "Name of the group you want to delete"
                nct --help "get help with delete group"
            }

            nct item "Move an item to the Trash." {
                nct '<Item>' "Name of the item you want to delete"
                nct --vault "Specify the <vault> to delete the item from. If not specified the item is searched for in all vaults."
                nct --help "get help with delete item"
            }

            nct trash "Empties the trash for a given vault." {
                nct '<Vault>' "Name of the vault you want to empty the trash"
                nct --help "get help with delete trash"
            }

            nct user "Completely remove a user." {
                nct '<Group>' "Name of the user you want to delete"
                nct --help "get help with delete user"
            }

            nct vault "Remove a vault." {
                nct '<Group>' "Name of the vault you want to delete"
                nct --help "get help with delete vault"
            }

            nct --help "get help with delete"
        }

        nct edit "Edit an object." {
            nct group "Edit a group in your 1Password account." {
                nct '<Group>' "Name of the group you want to modify"
                nct --description "The new description of the group, for example: 'development keys'"
                nct --name "The new <name> of the group, for example: 'developers"
                nct --help "get help with edit group"
            }

            nct item "Edit a item in your 1Password account." {
                nct '<Item>' "Name of the Item you want to modify"
                nct --generate-password " give the item a randomly generated password"
                nct --vault "look for the item in this vault"
                nct --help "get help with edit item"
            }

            nct user "Edit the name or travel mode state of a user" {
                nct '<User>' "Name of the user you want to modify"
                nct --name "Set the name of the user to to <name>"
                nct --travelmode "<on|off> Enable or disable travel mode. (default )"
                nct --help "get help with edit user"
            }
        }

        nct encode "Encode the JSON needed to create an item." {
            nct --help "get help with encode"
        }

        nct forget "Remove a 1Password account from this device." {
            nct '<Account>' "Name of the account you want to forget"
            nct --help "get help with forget"
        }

        nct get "Get details about an object." {
            nct account "Get details about your account." {
                nct --help "get help with get account"
            }

            nct document "Download a document." {
                nct '<Document>' "Name of the document you want to get"
                nct --include-trash "Include deleted documents."
                nct --output "Save the document to <file path> instead of printing it to stdout. This is especially useful in some shells to preserve the original encoding of the file. The destination file must be empty or non-existent."
                nct --vault "Look for the document in this <vault>. Specify <vault> by UUID or name."
                nct --help "get help with get document"
            }

            nct group "Get details about a group." {
                nct '<Group>' "Name of the group you want to get"
                nct --help "get help with get group"
            }

            nct item "Get item details." {
                nct '<Item>' "Name of the item you want to get"
                nct --fields "only return data from these fields"
                nct --format "return data in this format (CSV or JSON) (use with --fields)"
                nct --include-trash "Include items in the Trash. Always on for an item specified by UUID."
                nct --share-link "get a shareable link for the item"
                nct --vault "Look for the item in <vault>. Specify <vault> by UUID or name."
                nct --help "get help with get item"
            }

            nct template "Get an item template." {
                nct '<Category>' "Name of the category you want to get. Categories are: Login, Secure Note, ..."
                nct --help "get help with get template"
            }

            nct totp "Get the one-time password for an item." {
                nct '<Item>' "Name of the item you want to get the totp"
                nct --vault "Look for the item in <vault>. Specify <vault> by UUID or name."
                nct --help "get help with get totp"
            }

            nct user "Get details about a user." {
                nct '<User>' "Name of the user you want to get"
                nct --fingerprint "If set, returns the user's public key fingerprint"
                nct --publickey "If set, returns the user's public key"
                nct --help "get help with get user"
            }

            nct vault "Get details about a vault." {
                nct '<Vault>' "Name of the vault you want to get"
                nct --help "get help with get vault"
            }

            nct --help "get help with get"
        }

        nct help "Help about any command" {
            nct "add" "Grant access to groups or vaults"
            nct "confirm" "Confirm a user"
            nct "create" "Create an object"
            nct "delete" "Remove an object"
            nct "edit" "Edit an object"
            nct "encode" "Encode the JSON needed to create an item"
            nct "forget" "Remove a 1Password account from this device"
            nct "get" "Get details about an object"
            nct "help" "Get help for a command."
            nct "list" "List objects and events"
            nct "reactivate" "Reactivate a suspended user"
            nct "remove" "Revoke access to groups or vaults"
            nct "signin" "Sign in to a 1Password account"
            nct "signout" "Sign out of a 1Password account"
            nct "suspend" "Suspend a user"
            nct "update" "Check for updates"
            nct --help "get help for op"
        }

        nct list "List objects and events." {
            nct documents "Get a list of documents." {
                nct --include-trash "Include documents in the Trash"
                nct --vault "vault List documents in vault"
                nct --help "get help with list documents"
            }

            nct events "Get a list of events from the Activity Log." {
                nct --eventid "Return the events after the event with ID <event_ID>"
                nct --older "Return the events *before* the event with ID <event_ID>"
                nct --help "get help with list events"
            }

            nct groups "Get the list of groups." {
                nct --vault "List groups who have direct access to <vault>. Specify <vault> by name or UUID."
                nct --help "get help with list groups"
            }

            nct items "Get a list of items." {
                nct --include-trash "Include items in the Trash"
                nct --vault "List items in <vault>. Specify <vault> by name or UUID."
                nct --help "get help with list items"
            }

            nct templates "Get the list of templates." {
                nct --help "get help with list templates"
            }

            nct users "Get the list of users." {
                nct --group "List users who belong to this group. Specify group by name or UUID."
                nct --vault "List users who have direct access to this vault. Specify vault by name or UUID"
                nct --help "get help with list users"
            }

            nct vaults "Get the list of vaults." {
                nct --group "List vaults <group> has access to. Specify <group> by name or UUID."
                nct --help "get help with list vaults"
            }

            nct --help "get help with list"
        }

        nct reactivate "Reactivate a suspended user." {
            nct '<User>' "User you want to reactivate"
            nct --help "get help with reactivate"
        }

        nct remove "Revoke access for users or groups to groups or vaults."{
            nct group "Revoke a group's access to a vault." {
                nct '<Group>' "Name of the group you want to remove"
                nct '<Vault>' "Name of the vault where the group is stored"
                nct --help "get help with remove group"
            }

            nct user "Revoke a user's access to a vault or group." {
                nct '<User>' "Name of the group you want to remove"
                nct '[<Group>|<Vault>]' "Name of the group or vault where the user has access"
                nct --help "get help with remove user"
            }

            nct --help "get help with remove"
        }

        nct signin "Sign in to your 1Password account." {
            nct '<sign_in_address>' "Your sign in address for your 1Password account. For example my.1password.com"
            nct '<email_address>' "Your email address for 1Password account"
            nct '<secret_key>' "Your secret key for your 1Password account"
            nct --raw "output the raw session token"
            nct --shorthand "use <name> as short account name for new account"
            nct --help "get help with signin"
        }

        nct signout "Sign out of your 1Password account." {
            nct --forget "removes the account from the local configuration file"
            nct --help "get help with signout"
        }

        nct suspend "Suspend a user." {
            nct '<User>' "Name of the user you want to suspend"
            nct --help "get help with suspend"
        }

        nct update "Check for updates." {
            nct --help "get help with update"
        }

        nct --account "account to use when multiple sessions are active"
        nct --help "get help for op"
        nct --session "raw session token obtained via 'op signin --raw'"
        nct --version "version for op"
    }

    Get-CommandTreeCompletion $wordToComplete $commandAst $commandTree
}

Register-ArgumentCompleter -CommandName op -Native -ScriptBlock $function:opCompletion