idonethis-cli 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/adapters/cli.rb CHANGED
@@ -1,87 +1,92 @@
1
- require 'internet'
2
- require 'views/cli'
3
- require 'use_cases/new'
4
- require 'use_cases/list'
5
- require 'settings_file'
6
-
7
- module Idonethis::Adapters
8
- class Cli
9
- class << self
10
- def run(argv={})
11
- args = parse(argv)
12
-
13
- command,*rest = argv
14
-
15
- command = "help" unless command
16
-
17
- log = choose_log(args)
18
-
19
- args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)})
20
- credential = Settings.credential
21
-
22
- log.call "args: #{args}, command: #{command}, rest: #{rest}"
23
-
24
- use_case = choose command.to_sym, rest
25
-
26
- unless use_case
27
- puts "No command <#{command.to_sym}> found"
28
- return
29
- end
30
-
31
- use_case.call credential, args
32
- end
33
-
34
- private
35
-
36
- def choose(command, opts)
37
- use_cases = {
38
- list: Idonethis::UseCases::List.method(:apply),
39
- new: Idonethis::UseCases::New.method(:apply),
40
- config: Idonethis::UseCases::Config.method(:apply),
41
- git: Idonethis::UseCases::Git.method(:apply),
42
- help: ->(credential, args) { puts "TODO: implement help" }
43
- }
44
-
45
- if command == :list && opts.include?("teams")
46
- return ->(credential, args) {
47
- Idonethis::UseCases::Teams.apply(credential, args.merge(view: Idonethis::Adapters::Views::Cli::Teams.method(:apply)))
48
- }
49
- end
50
-
51
- use_case = use_cases[command]
52
- end
53
-
54
- def choose_log(args={})
55
- args[:verbose] == true ? ->(msg){puts "[LOG] #{msg}"} : ->(_){}
56
- end
57
-
58
- def parse(argv={})
59
- args = {}
60
-
61
- require 'optparse'
62
-
63
- OptionParser.new do |opts|
64
- opts.banner = "Usage: command [options]"
65
-
66
- opts.on("-v", "--verbose", "Run verbosely") do |v|
67
- args[:verbose] = v
68
- end
69
-
70
- opts.on("-m MESSAGE", "Message") do |m|
71
- args[:message] = m
72
- end
73
-
74
- opts.on("-d", "Dry run") do |_|
75
- args[:dry_run] = true
76
- end
77
-
78
- opts.on("-t TEAM", "--team TEAM" "Run against this team") do |team_name|
79
- args[:team] = team_name
80
- end
81
- end.parse!
82
-
83
- args
84
- end
85
- end
86
- end
87
- end
1
+ require 'internet'
2
+ require 'views/cli'
3
+ require 'use_cases/new'
4
+ require 'use_cases/list'
5
+ require 'settings_file'
6
+ require 'io/directory_info'
7
+
8
+ module Idonethis::Adapters
9
+ class Cli
10
+ class << self
11
+ def run(argv={})
12
+ args = parse(argv)
13
+
14
+ command,*rest = argv
15
+
16
+ command = "help" unless command
17
+
18
+ log = choose_log(args)
19
+
20
+ args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)})
21
+ credential = Settings.credential
22
+
23
+ log.call "args: #{args}, command: #{command}, rest: #{rest}"
24
+
25
+ use_case = choose command.to_sym, rest
26
+
27
+ unless use_case
28
+ log.call "No command <#{command.to_sym}> found"
29
+ return
30
+ end
31
+
32
+ use_case.call credential, args
33
+ end
34
+
35
+ private
36
+
37
+ def choose(command, opts)
38
+ use_cases = {
39
+ list: Idonethis::UseCases::List.method(:apply),
40
+ new: Idonethis::UseCases::New.method(:apply),
41
+ config: Idonethis::UseCases::Config.method(:apply),
42
+ git: ->(_, args) { Idonethis::UseCases::Git.apply(_, args.merge(git: Idonethis::Adapters::Git, view: ->(msg) { puts msg }, fs: Idonethis::Adapters::IO::DirectoryInfo))},
43
+ help: ->(credential, args) { puts "TODO: implement help" }
44
+ }
45
+
46
+ if command == :list && opts.include?("teams")
47
+ return ->(credential, args) {
48
+ Idonethis::UseCases::Teams.apply(credential, args.merge(view: Idonethis::Adapters::Views::Cli::Teams.method(:apply)))
49
+ }
50
+ end
51
+
52
+ use_case = use_cases[command]
53
+ end
54
+
55
+ def choose_log(args={})
56
+ args[:verbose] == true ? ->(msg){puts "[LOG] #{msg}"} : ->(_){}
57
+ end
58
+
59
+ def parse(argv={})
60
+ args = {}
61
+
62
+ require 'optparse'
63
+
64
+ OptionParser.new do |opts|
65
+ opts.banner = "Usage: command [options]"
66
+
67
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
68
+ args[:verbose] = v
69
+ end
70
+
71
+ opts.on("-m MESSAGE", "Message") do |m|
72
+ args[:message] = m
73
+ end
74
+
75
+ opts.on("-d", "Dry run") do |_|
76
+ args[:dry_run] = true
77
+ end
78
+
79
+ opts.on("-t TEAM", "--team TEAM" "Run against this team") do |team_name|
80
+ args[:team] = team_name
81
+ end
82
+
83
+ opts.on("-s WHEN", "--since WHEN" "Show git commits since when") do |value|
84
+ args[:since] = value
85
+ end
86
+ end.parse!
87
+
88
+ args
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,18 @@
1
+ module Idonethis::Adapters
2
+ module Git
3
+ class << self
4
+ def commits(dir, since)
5
+ require 'git'
6
+
7
+ since_when = case since
8
+ when 'yesterday'
9
+ '1am yesterday'
10
+ else
11
+ '1am'
12
+ end
13
+
14
+ ::Git.open(dir).log.since(since_when)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,15 +1,15 @@
1
- module Idonethis::Adapters
2
- module Internet
3
- class << self
4
- require 'restclient'
5
-
6
- def get(url, headers = {}, body = {})
7
- RestClient.get(url, headers)
8
- end
9
-
10
- def post(url, headers = {}, body = {})
11
- RestClient.post(url, body, headers)
12
- end
13
- end
14
- end
1
+ module Idonethis::Adapters
2
+ module Internet
3
+ class << self
4
+ require 'restclient'
5
+
6
+ def get(url, headers = {}, body = {})
7
+ RestClient.get(url, headers)
8
+ end
9
+
10
+ def post(url, headers = {}, body = {})
11
+ RestClient.post(url, body, headers)
12
+ end
13
+ end
14
+ end
15
15
  end
@@ -0,0 +1,33 @@
1
+ module Idonethis::Adapters
2
+ module IO
3
+ module DirectoryInfo
4
+ class << self
5
+ def modified_today?(dir)
6
+ time,now = File.ctime(dir),Time.now
7
+
8
+ _in(dir).select{|it| any_file_inside_changed?(it, time, now) }
9
+ end
10
+
11
+ private
12
+
13
+ def any_file_inside_changed?(dir, time, now)
14
+ Dir["#{dir}/**/**"].each do |file|
15
+ return true if today?(File.ctime(file), now)
16
+ end
17
+ return false
18
+ end
19
+
20
+ def today?(time, now)
21
+ time.year == now.year && time.month == now.month && time.day == now.day
22
+ end
23
+
24
+ def _in(dir)
25
+ Dir.entries(dir).
26
+ reject{|it| ["..", "."].include?(it) }.
27
+ select{|it| File.directory?(File.join(dir, it))}.
28
+ map{ |it| File.expand_path(File.join(dir, it))}
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,20 +1,20 @@
1
- module Idonethis::Adapters
2
- module Settings
3
- class << self
4
- def credential
5
- from_disk || from_env
6
- end
7
-
8
- private
9
-
10
- def from_disk
11
- require 'yaml'
12
- YAML.load_file Idonethis::SettingsFile.path if Idonethis::SettingsFile.exists?
13
- end
14
-
15
- def from_env
16
- { token: ENV["TOKEN"], team: ENV["TEAM"] }
17
- end
18
- end
19
- end
1
+ module Idonethis::Adapters
2
+ module Settings
3
+ class << self
4
+ def credential
5
+ from_disk || from_env
6
+ end
7
+
8
+ private
9
+
10
+ def from_disk
11
+ require 'yaml'
12
+ YAML.load_file Idonethis::SettingsFile.path if Idonethis::SettingsFile.exists?
13
+ end
14
+
15
+ def from_env
16
+ { token: ENV["TOKEN"], team: ENV["TEAM"] }
17
+ end
18
+ end
19
+ end
20
20
  end
@@ -1,36 +1,36 @@
1
- module Idonethis::Adapters
2
- module Views
3
- module Cli
4
- module List
5
- class << self
6
- def apply(dones=[])
7
- dones.select{|it| it["is_goal"] == false}.each_with_index do |d,i|
8
- #{
9
- # "id"=>22609300, "created"=>"2015-09-09T06:26:07.120", "updated"=>"2015-09-19T13:00:03.570", "markedup_text"=>"fix api smoke", "done_date"=>"2015-09-20", "owner"=>"ben.biddington",
10
- # "team_short_name"=>"benbiddington-personal", "tags"=>[], "likes"=>[], "comments"=>[], "meta_data"=>{}, "is_goal"=>true, "goal_completed"=>false,
11
- # "url"=>"https://idonethis.com/api/v0.1/dones/22609300/", "team"=>"https://idonethis.com/api/v0.1/teams/benbiddington-personal/", "raw_text"=>"[ ] fix api smoke", "permalink"=>"https://idonethis.com/done/22609300/"}
12
- # puts d.inspect
13
- printf("%-5s", i+1); print(%Q{#{d["created"]} #{d["team_short_name"]} }); printf("%-20s", d["owner"]); print(%Q{ -- #{d["raw_text"].slice(0,150)}}); print("\n")
14
- end
15
- end
16
- end
17
- end
18
-
19
- module Teams
20
- class << self
21
- def apply(teams=[])
22
- teams.select.each_with_index do |d,i|
23
- #{
24
- # "updated"=>"2015-05-20T23:53:58.831", "created"=>"2015-05-20T23:53:48.357",
25
- # "done_count"=>138,
26
- # "url"=>"https://idonethis.com/api/v0.1/teams/benbiddington-personal/",
27
- # "name"=>"ben.biddington personal", "short_name"=>"benbiddington-personal",
28
- # "dones"=>"https://idonethis.com/api/v0.1/dones/?team=benbiddington-personal", "is_personal"=>true, "permalink"=>"https://idonethis.com/cal/benbiddington-personal/"}
29
- printf("%-5s", i+1); print(%Q{#{d["updated"]}}); print(" "); printf("%-30s", d["name"]); printf("%-5s", %Q{(#{d["done_count"]})}); print(" "); print(%Q{#{d["permalink"]}}); print("\n")
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
1
+ module Idonethis::Adapters
2
+ module Views
3
+ module Cli
4
+ module List
5
+ class << self
6
+ def apply(dones=[])
7
+ dones.select{|it| it["is_goal"] == false}.each_with_index do |d,i|
8
+ #{
9
+ # "id"=>22609300, "created"=>"2015-09-09T06:26:07.120", "updated"=>"2015-09-19T13:00:03.570", "markedup_text"=>"fix api smoke", "done_date"=>"2015-09-20", "owner"=>"ben.biddington",
10
+ # "team_short_name"=>"benbiddington-personal", "tags"=>[], "likes"=>[], "comments"=>[], "meta_data"=>{}, "is_goal"=>true, "goal_completed"=>false,
11
+ # "url"=>"https://idonethis.com/api/v0.1/dones/22609300/", "team"=>"https://idonethis.com/api/v0.1/teams/benbiddington-personal/", "raw_text"=>"[ ] fix api smoke", "permalink"=>"https://idonethis.com/done/22609300/"}
12
+ # puts d.inspect
13
+ printf("%-5s", i+1); print(%Q{#{d["created"]} #{d["team_short_name"]} }); printf("%-20s", d["owner"]); print(%Q{ -- #{d["raw_text"].slice(0,150)}}); print("\n")
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ module Teams
20
+ class << self
21
+ def apply(teams=[])
22
+ teams.select.each_with_index do |d,i|
23
+ #{
24
+ # "updated"=>"2015-05-20T23:53:58.831", "created"=>"2015-05-20T23:53:48.357",
25
+ # "done_count"=>138,
26
+ # "url"=>"https://idonethis.com/api/v0.1/teams/benbiddington-personal/",
27
+ # "name"=>"ben.biddington personal", "short_name"=>"benbiddington-personal",
28
+ # "dones"=>"https://idonethis.com/api/v0.1/dones/?team=benbiddington-personal", "is_personal"=>true, "permalink"=>"https://idonethis.com/cal/benbiddington-personal/"}
29
+ printf("%-5s", i+1); print(%Q{#{d["updated"]}}); print(" "); printf("%-30s", d["name"]); printf("%-5s", %Q{(#{d["done_count"]})}); print(" "); print(%Q{#{d["permalink"]}}); print("\n")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/idonethis.rb CHANGED
@@ -1,10 +1,10 @@
1
- require "idonethis/cli/version"
2
-
3
- lib = File.expand_path(File.join(File.dirname(__FILE__), "idonethis"))
4
- adapters = File.expand_path(File.join(File.dirname(__FILE__), "adapters"))
5
-
6
- $:.unshift lib
7
- $:.unshift adapters
8
-
9
- Dir.glob(File.join(lib, "**", "*.rb")).each {|file| require file}
10
- Dir.glob(File.join(adapters, "**", "*.rb")).each {|file| require file}
1
+ require "idonethis/cli/version"
2
+
3
+ lib = File.expand_path(File.join(File.dirname(__FILE__), "idonethis"))
4
+ adapters = File.expand_path(File.join(File.dirname(__FILE__), "adapters"))
5
+
6
+ $:.unshift lib
7
+ $:.unshift adapters
8
+
9
+ Dir.glob(File.join(lib, "**", "*.rb")).each {|file| require file}
10
+ Dir.glob(File.join(adapters, "**", "*.rb")).each {|file| require file}
@@ -1,5 +1,5 @@
1
- module Idonethis
2
- module Cli
3
- VERSION = "0.12.0"
4
- end
5
- end
1
+ module Idonethis
2
+ module Cli
3
+ VERSION = "0.13.0"
4
+ end
5
+ end
@@ -1,27 +1,27 @@
1
- module Idonethis
2
- module Index
3
- class << self
4
- def dones(params={})
5
- %Q{#{dones_base_earl}?#{params.map{|k,v| "#{k}=#{v}"}.join('&')}}
6
- end
7
-
8
- def teams()
9
- teams_base_earl
10
- end
11
-
12
- private
13
-
14
- def dones_base_earl
15
- "#{base_earl}/dones/"
16
- end
17
-
18
- def teams_base_earl
19
- "#{base_earl}/teams/"
20
- end
21
-
22
- def base_earl
23
- "https://idonethis.com/api/v0.1"
24
- end
25
- end
26
- end
1
+ module Idonethis
2
+ module Index
3
+ class << self
4
+ def dones(params={})
5
+ %Q{#{dones_base_earl}?#{params.map{|k,v| "#{k}=#{v}"}.join('&')}}
6
+ end
7
+
8
+ def teams()
9
+ teams_base_earl
10
+ end
11
+
12
+ private
13
+
14
+ def dones_base_earl
15
+ "#{base_earl}/dones/"
16
+ end
17
+
18
+ def teams_base_earl
19
+ "#{base_earl}/teams/"
20
+ end
21
+
22
+ def base_earl
23
+ "https://idonethis.com/api/v0.1"
24
+ end
25
+ end
26
+ end
27
27
  end