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
// Copyright 2016 LambdaStack All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use clap::{App, Arg, SubCommand};

pub fn build_cli<'a>(app: &str, home: &'a str, version: &'a str) -> App<'a, 'a> {
  App::new(app)
    .about("S3 Client and Benchmarking Utility that can access AWS S3, Ceph or any third party S3 enable environment.")
    .author("Chris Jones")
    .version(version)
    .after_help("For more information about a specific command, try `s3lsio <command> --help`\nSource code for s3lsio available at: https://github.com/lambdastackio/s3lsio")
//    .arg(Arg::with_name("admin")
//      .short("a")
//      .long("admin")
//      .help("Ceph RGW Admin"))
   .arg(Arg::with_name("bench")
      .short("b")
      .long("bench")
      .value_name("Format: N:N:N:N:N:A (N - Number, A - Alpha)")
      .help("Benchmarking command: AAA:BBB:CCC:DDD:EEE:F AAA - Duration in seconds, BBB - Iterations (must be 0 if using duration), CCC - Virtual Users (threads), DDD - Hosts (only 1 for now), EEE - Ramp up time (0 - Thundering Heard, anythig else spread out), F - Summary or Detail (must be S or D). MUST set `-f noneall` when using this option.")
      .takes_value(true))
    .arg(Arg::with_name("config")
      .short("c")
      .long("config")
      .value_name("FILE")
      .default_value(home)
      .help("Sets a custom config file.")
      .takes_value(true))
   .arg(Arg::with_name("endpoint")
      .short("e")
      .long("endpoint")
      .value_name("URL:<port>")
      .help("Sets a custom endpoint URL:<port> (port is optional). Default is AWS default endpoints based on Region")
      .takes_value(true))
   .arg(Arg::with_name("output-format")
      .short("f")
      .long("output-format")
      .default_value("pretty-json")
      .value_name("pretty-json or json or plain or serialize")
      .help("Specifies the output to stdout (and disk in some cases). Options are json, none, noneall, pretty-json, plain, serialize")
      .takes_value(true))
   .arg(Arg::with_name("generate-bash-completions")
     .short("g")
     .long("generate-bash-completions")
     .help("Outputs bash completions"))
   .arg(Arg::with_name("bucket-virtual-host")
     .short("h")
     .long("bucket-virtual-host")
     .help("Overrides the default of TRUE for virtual buckets. Useful for non AWS environments"))
   .arg(Arg::with_name("keep-alive")
     .short("k")
     .long("keep-alive")
     .help("Overrides the default of TRUE for keep-alive. Create a single connection per thread. False creates a connection for every iteration"))
   .arg(Arg::with_name("output-color")
      .short("l")
      .long("output-color")
      .default_value("green")
      .value_name("green or red or blue or yellow or white or normal")
      .help("Specifies the output color.")
      .takes_value(true))
   .arg(Arg::with_name("compute-hash")
      .short("m")
      .long("compute-hash")
      .help("Overrides the default of FALSE for compute_hash. By default objects uploaded do not have a hash computed"))
   .arg(Arg::with_name("output-bench-format")
      .short("o")
      .long("output-bench-format")
      .default_value("pretty-json")
      .value_name("pretty-json or json or plain or serialize")
      .help("Specifies the output to stdout (and disk in some cases). Options are json, none, noneall, pretty-json, plain, serialize")
      .takes_value(true))
   .arg(Arg::with_name("proxy")
      .short("p")
      .long("proxy")
      .value_name("URL:<port>")
      .help("Sets a custom proxy URL:<port>. Default is to use http(s)_proxy and no_proxy")
      .takes_value(true))
   .arg(Arg::with_name("quiet")
      .short("q")
      .long("quiet")
      .help("No output is produced"))
   .arg(Arg::with_name("region")
      .short("r")
      .long("region")
      .value_name("Region")
      .default_value("UsEast1")
      .help("Sets S3 Region.")
      .takes_value(true))
   .arg(Arg::with_name("signature")
      .short("s")
      .long("signature")
      .value_name("V2 or V4")
      .default_value("V4")
      .help("Sets an API Signature version.")
      .takes_value(true))
   .arg(Arg::with_name("time")
      .short("t")
      .long("time")
      .help("Track time duration of operation(s)"))
   .arg(Arg::with_name("yes")
      .short("y")
      .long("yes")
      .help("Answer yes automatically"))
   .subcommand(SubCommand::with_name("abort")
      .about("Abort multipart upload: s3lsio abort <upload_id> s3://<bucket>/<object>")
      .arg_from_usage("[upload_id] 'Multipart Upload ID'")
      .arg_from_usage("[bucket] 'Bucket name'"))
   .subcommand(SubCommand::with_name("acl")
      .about("Bucket ACLs: s3lsio acl s3://<bucket>")
      .subcommand(SubCommand::with_name("get")
         .about("Get Bucket ACLs: s3lsio acl get s3://<bucket>")
         .arg_from_usage("[bucket] 'Bucket name'"))
      .subcommand(SubCommand::with_name("set")
         .about("Set Bucket ACLs: s3lsio acl set <acls> s3://<bucket>")
         .arg_from_usage("[acls] 'ACLs - public-read, public-readwrite, private'")
         .arg_from_usage("[bucket] 'Bucket name'")))
   .subcommand(SubCommand::with_name("bench")
      .about("Benchmarking: s3lsio bench <command> <options>")
      .subcommand(SubCommand::with_name("gen")
         .about("Benchmarking Gen files (only if desired): s3lsio bench gen <path> s3://<bucket>/<object> <size>. Generates synthetic files of a given size.")
         .arg_from_usage("[bucket] 'Bucket name'")
         .arg_from_usage("[path] 'Path'")
         .arg_from_usage("[size] 'Size of file'"))
      .subcommand(SubCommand::with_name("get")
         .about("Benchmarking GET Object: s3lsio bench get s3://<bucket>/<object>")
         .arg_from_usage("[bucket] 'Bucket name/object name'"))
      .subcommand(SubCommand::with_name("put")
         .about("Benchmarking PUT Object: s3lsio bench put s3://<bucket>/<object> <size> <size-of-parts>")
         .arg_from_usage("[bucket] 'Bucket name'")
         .arg_from_usage("[size] 'Size of object in bytes'")
         .arg_from_usage("[size_of_parts] 'Size of each part for multipart upload'"))
      .subcommand(SubCommand::with_name("range")
         .about("Benchmarking Byte-Range request of Object: s3lsio bench range <offset> <len> s3://<bucket>/<object>")
         .arg_from_usage("[offset] 'Range begin offset'")
         .arg_from_usage("[len] 'Range len'")
         .arg_from_usage("[bucket] 'Bucket name/object name'")))
   .subcommand(SubCommand::with_name("head")
      .about("Head Bucket or Object: s3lsio head s3://<bucket> or s3lsio head s3://<bucket>/<object>")
      .arg_from_usage("[bucket] 'Bucket name'"))
   .subcommand(SubCommand::with_name("ls")
      .about("List Buckets or Objects in bucket with optional version tag: s3lsio ls OR s3lsio ls s3://<bucket>/<prefix> <option>")
      .arg_from_usage("[bucket] 'Bucket name'")
      .arg_from_usage("[option] 'ver or multi'")
      .arg_from_usage("[upload_id] 'multipart upload ID option'"))
   .subcommand(SubCommand::with_name("mb")
      .about("Make Bucket: s3lsio mb s3://<bucket>")
      .arg_from_usage("[bucket] 'Bucket name'"))
   .subcommand(SubCommand::with_name("rb")
      .about("Remove Bucket: s3lsio rb s3://<bucket>")
      .arg_from_usage("[bucket] 'Bucket name'"))
   .subcommand(SubCommand::with_name("rm")
      .about("Remove Object and/or Object version: s3lsio rm s3://<bucket>/<object> <version>")
      .arg_from_usage("[bucket] 'Bucket name'")
      .arg_from_usage("[version] 'Version'"))
   .subcommand(SubCommand::with_name("get")
      .about("Get Object (use `cp`): s3lsio get s3://<bucket>/<object> <path>")
      .arg_from_usage("[bucket] 'Bucket name'")
      .arg_from_usage("[path] 'Path'"))
   .subcommand(SubCommand::with_name("cp")
      .about("Copy Object: s3lsio cp s3://<bucket>/<object> <path> OR s3lsio cp <path> s3://<bucket>/<object> <size of parts>")
      .arg_from_usage("[bucket] 'Bucket name/object name'")
      .arg_from_usage("[path] 'Path'")
      .arg_from_usage("[size] 'Size of parts'"))
   .subcommand(SubCommand::with_name("put")
      .about("Put Object (use `cp`) <size of parts> is optional: s3lsio put <path> s3://<bucket>/<object> <size of parts>")
      .arg_from_usage("[path] 'Path of where to find object'")
      .arg_from_usage("[bucket] 'Bucket name'")
      .arg_from_usage("[size] 'Size of parts for multipart upload'"))
   .subcommand(SubCommand::with_name("range")
      .about("Byte-Range request of Object: s3lsio range <offset> <len> s3://<bucket>/<object> <path>")
      .arg_from_usage("[offset] 'Range begin offset'")
      .arg_from_usage("[len] 'Range len'")
      .arg_from_usage("[bucket] 'Bucket name/object name'")
      .arg_from_usage("[path] 'Path'"))
   .subcommand(SubCommand::with_name("ver")
      .about("Shows Bucket Versioning: s3lsio ver get s3://<bucket>")
      .subcommand(SubCommand::with_name("get")
         .arg_from_usage("[bucket] 'Bucket name'"))
      .subcommand(SubCommand::with_name("set")
         .about("Enables Bucket Versioning: s3lsio ver set on|off s3://<bucket>")
         .arg_from_usage("[ver] 'On or Off'")
         .arg_from_usage("[bucket] 'Bucket name'")))
    // Ceph RGW Admin Section...
   .subcommand(SubCommand::with_name("admin")
       .about("Admin Options: s3lsio admin <command> <options>")
       .subcommand(SubCommand::with_name("bucket")
          .about("Admin Bucket Options: s3lsio admin bucket <command> s3://<bucket> <user> <stats> <fix> <check>")
          .arg_from_usage("[command] 'Commands: delete - Delete, ls - List, stats - stats, link - Link, policy - Policy, unlink - Unlink, index - Index'")
          .arg_from_usage("[bucket] 'Bucket name or Bucket/Object name'")
          .arg_from_usage("[user] 'User ID (uid) (Not required on delete)'")
          .arg_from_usage("[stats] '(Optional) - true or false. Default is false. Only used with stats command'")
          .arg_from_usage("[fix] '(Optional) - true or false. Default is false. Only used with index command'")
          .arg_from_usage("[check] '(Optional) - true or false. Default is false. Only used with index command'"))
       .subcommand(SubCommand::with_name("object")
          .about("Admin Object Options: s3lsio admin object <command> s3://<bucket>/<object> <user>")
          .arg_from_usage("[command] 'Commands: delete - Delete object for given user'")
          .arg_from_usage("[bucket] 'Bucket name or Bucket/Object name'")
          .arg_from_usage("[user] 'User ID (uid)'"))
       .subcommand(SubCommand::with_name("quota")
          .about("Admin Quota Options: s3lsio admin quota <user> <command> <action> <size> <count>")
          .arg_from_usage("[user] 'User ID (uid)'")
          .arg_from_usage("[command] 'Commands: bucket - Bucket, user - User'")
          .arg_from_usage("[action] 'Action: get - Get, set - Set, enable - Enable quota, disable - Disable quota'")
          .arg_from_usage("[size] 'Quota size - max size in KB (defaults to 0)'")
          .arg_from_usage("[count] 'Quota object count - max number of objects (defaults to 0)'"))
       .subcommand(SubCommand::with_name("cap")
          .about("Admin Caps Admin User: s3lsio admin cap <user> <caps>")
          .arg_from_usage("[user] 'User ID (uid)'")
          .arg_from_usage("[caps] 'Admin Capability of user'"))
       .subcommand(SubCommand::with_name("user")
          .about("Admin User Options: s3lsio admin user <commands> [options]")
          .subcommand(SubCommand::with_name("create")
             .about("Admin Create User: s3lsio -a user create <user> <display_name> <email> <access_key> <secret_key> <caps>")
             .arg_from_usage("[user] 'User ID (uid)'")
             .arg_from_usage("[display_name] 'Display name - multi-word names should be inside of quotation marks'")
             .arg_from_usage("[email] '(Optional) User email (optional)'")
             .arg_from_usage("[access_key] '(Optional) Access Key ID'")
             .arg_from_usage("[secret_key] '(Optional) Secret Key ID'")
             .arg_from_usage("[suspended] '(Optional) Suspend user. Defaults to false'")
             .arg_from_usage("[caps] '(Optional) Capability of user'"))
          .subcommand(SubCommand::with_name("delete")
             .about("Admin Delete User: s3lsio -a user delete <user> <purge_data>")
             .arg_from_usage("[user] 'User ID (uid)'")
             .arg_from_usage("[purge_data] '(Optional) Purge data. Defaults to false'"))
          .subcommand(SubCommand::with_name("modify")
             .about("Admin Modify User: s3lsio -a user modify <user> <purge_data>")
             .arg_from_usage("[user] 'User ID (uid)'")
             .arg_from_usage("[display_name] '(Optional) Display name - multi-word names should be inside of quotation marks'")
             .arg_from_usage("[suspended] '(Optional) Suspend user. Defaults to false'")
             .arg_from_usage("[email] '(Optional) User email'")
             .arg_from_usage("[access_key] '(Optional) Access Key ID (optional)'")
             .arg_from_usage("[secret_key] '(Optional) Secret Key ID (optional)'")
             .arg_from_usage("[caps] '(Optional) Secret Key ID (optional)'")
             .arg_from_usage("[max_buckets] '(Optional) Maximum number of buckets. Defaults to 1000'"))
          .subcommand(SubCommand::with_name("get")
             .about("Admin Get User: s3lsio -a user get <user>")
             .arg_from_usage("[user] 'User ID (uid)'"))
          .subcommand(SubCommand::with_name("ls")
             .about("Admin List Users: s3lsio -a user ls")))
       .subcommand(SubCommand::with_name("usage")
          .about("Admin Usage Options: s3lsio admin usage ls <user> <start> <end> <show_entries> <show_summary>")
          .subcommand(SubCommand::with_name("ls")
             .arg_from_usage("[user] 'User ID (uid). If not supplied then the command applies to all users'")
             .arg_from_usage("[start] 'Start DateTime [yyyy-mm-dd hh:mm:ss] (optional)'")
             .arg_from_usage("[end] 'End DateTime [yyyy-mm-dd hh:mm:ss] (optional)'")
             .arg_from_usage("[show_entries] 'Specifies whether data entries should be returned [true or false] (Default is false)'")
             .arg_from_usage("[show_summary] 'Specifies whether data summary should be returned [true or false] (Default is false)'"))
          .subcommand(SubCommand::with_name("trim")
             .about("Admin Usage Options: s3lsio -a usage trim <user> <start> <end> <remove_all>")
             .arg_from_usage("[user] 'User ID (uid). If not supplied then the command applies to all users'")
             .arg_from_usage("[start] 'Start DateTime [yyyy-mm-dd hh:mm:ss] (optional)'")
             .arg_from_usage("[end] 'End DateTime [yyyy-mm-dd hh:mm:ss] (optional)'")
             .arg_from_usage("[remove_all] 'Remove all usage data [true or false] (optional except when no user is supplied)'")))
       .subcommand(SubCommand::with_name("keys")
          .about("Admin Keys Options: s3lsio admin keys <command> [options]")
          .subcommand(SubCommand::with_name("create")
             .about("Admin Keys Create: s3lsio -a keys create <user> <access_key> <secret_key> <generate_key>")
             .arg_from_usage("[user] 'User ID (uid)'")
             .arg_from_usage("[generate_key] '(Optional) Generate keys. Default is true'")
             .arg_from_usage("[access_key] '(Optional) Access Key ID'")
             .arg_from_usage("[secret_key] '(Optional) Secret Key ID'"))
         .subcommand(SubCommand::with_name("delete")
             .about("Admin Delete Keys: s3lsio -a keys delete <access_key> <user>")
             .arg_from_usage("[access_key] 'Access Key ID'")
             .arg_from_usage("[user] '(Optional) User ID (uid)'"))))
}