|
@@ -1,4 +1,5 @@
|
1
|
1
|
using B2Classes;
|
|
2
|
+using CommandLine;
|
2
|
3
|
using Newtonsoft.Json;
|
3
|
4
|
using System;
|
4
|
5
|
using System.Collections.Generic;
|
|
@@ -11,35 +12,50 @@ using System.Threading.Tasks;
|
11
|
12
|
|
12
|
13
|
namespace B2Uploader
|
13
|
14
|
{
|
14
|
|
- class Program
|
|
15
|
+ class CmdLineOptions
|
15
|
16
|
{
|
16
|
|
- static void Main(string[] args)
|
17
|
|
- {
|
18
|
|
- if(args.Count() != 3)
|
19
|
|
- {
|
20
|
|
- Console.WriteLine("Need accountID, AppKey and Folder to upload");
|
21
|
|
- return;
|
22
|
|
- }
|
|
17
|
+ [Option('i', "accountid", HelpText = "Account ID", Required=true)]
|
|
18
|
+ public string AccountId { get; set; }
|
23
|
19
|
|
24
|
|
- if (!Directory.Exists(args[2]))
|
25
|
|
- {
|
26
|
|
- Console.WriteLine("Directory to upload MUST EXIST!");
|
27
|
|
- return;
|
28
|
|
- }
|
|
20
|
+ [Option('a', "appkey", HelpText = "Application Key", Required=true)]
|
|
21
|
+ public string ApplicationKey { get; set; }
|
29
|
22
|
|
30
|
|
- var auth = AuthorizeUser(args[0], args[1]);
|
31
|
|
- var buckets = ListBuckets(new ListBucketsRequest() { accountId = auth.accountId }, auth.authorizationToken, auth.apiUrl);
|
|
23
|
+ [Option('d', "directory", HelpText="Directory you want to upload", Required=true)]
|
|
24
|
+ public string Directory {get;set;}
|
32
|
25
|
|
33
|
|
- var bucket = buckets.buckets.First();
|
|
26
|
+ [Option('v', "verbose", HelpText="Verbose Output")]
|
|
27
|
+ public bool Verbose{get;set;}
|
|
28
|
+ }
|
34
|
29
|
|
35
|
|
- foreach(string s in Directory.GetFiles(args[2]))
|
36
|
|
- {
|
37
|
|
- var uploadURL = GetUploadURL(new GetUploadURLRequest { bucketId = bucket.bucketId }, auth.apiUrl, auth.authorizationToken);
|
38
|
|
- var response = UploadFile(uploadURL.authorizationToken, "b2/x-auto", s, uploadURL.uploadUrl);
|
39
|
|
- }
|
|
30
|
+ class Program
|
|
31
|
+ {
|
|
32
|
+ static void Main(string[] args)
|
|
33
|
+ {
|
|
34
|
+ var result = CommandLine.Parser.Default.ParseArguments<CmdLineOptions>(args);
|
40
|
35
|
|
|
36
|
+ var existCode = result.MapResult(options => {
|
|
37
|
+ if (!Directory.Exists(options.Directory))
|
|
38
|
+ {
|
|
39
|
+ Console.WriteLine("Directory to upload MUST EXIST!");
|
|
40
|
+ return 0;
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ var auth = AuthorizeUser(options.AccountId, options.ApplicationKey);
|
|
44
|
+ var buckets = ListBuckets(new ListBucketsRequest() { accountId = auth.accountId }, auth.authorizationToken, auth.apiUrl);
|
41
|
45
|
|
|
46
|
+ var bucket = buckets.buckets.First();
|
42
|
47
|
|
|
48
|
+ foreach(string s in Directory.GetFiles(options.Directory))
|
|
49
|
+ {
|
|
50
|
+ var uploadURL = GetUploadURL(new GetUploadURLRequest { bucketId = bucket.bucketId }, auth.apiUrl, auth.authorizationToken);
|
|
51
|
+ var response = UploadFile(uploadURL.authorizationToken, "b2/x-auto", s, uploadURL.uploadUrl);
|
|
52
|
+ }
|
|
53
|
+ return 1;
|
|
54
|
+ },
|
|
55
|
+ errors =>{
|
|
56
|
+ Console.WriteLine(errors);
|
|
57
|
+ return 1;
|
|
58
|
+ });
|
43
|
59
|
}
|
44
|
60
|
|
45
|
61
|
static AuthorizeResponse AuthorizeUser(string accountId, string applicationKey)
|