Add an option for file/STDIN to allow for third party chart data #31
Conversation
…user flag is set at a time
…nd hand it to githubchart. GithubChart uses the data object directly
@@ -9,8 +9,37 @@ OptionParser.new do |opts| | |||
"Usage: githubchart (-u username) (-t type) path/for/new/image\n" | |||
opts.banner << 'Supported types: ' + GithubChart.supported.join(' ') | |||
opts.on('-uUSER', '--user=USER', 'Specify GitHub user to graph') do |user| | |||
if options.has_key?(:input) |
akerl
Sep 1, 2014
Owner
This should probably be "options.include? :input". has_key works, but include is the more conventional way for testing inclusion.
This should probably be "options.include? :input". has_key works, but include is the more conventional way for testing inclusion.
exit 1 | ||
end | ||
|
||
unless (input.eql? '-') || (File.exists?(input)) |
akerl
Sep 1, 2014
Owner
You may want to check "If file exists or (input equals '-' and stdin isn't a TTY", for sanity
You may want to check "If file exists or (input equals '-' and stdin isn't a TTY", for sanity
exit 1 | ||
end | ||
|
||
if input.eql? '-' |
akerl
Sep 1, 2014
Owner
You may want to make this and the preceding check one larger block. You can also use "fail "string"" to do the error message and exiting, so you could do something like:
if input.eql? '-'
fail 'No data provided on stdin' if STDIN.tty?
contents = STDIN.read
else
fail 'file does not exist' unless File.exists? input
contents = File.read input
end
You may want to make this and the preceding check one larger block. You can also use "fail "string"" to do the error message and exiting, so you could do something like:
if input.eql? '-'
fail 'No data provided on stdin' if STDIN.tty?
contents = STDIN.read
else
fail 'file does not exist' unless File.exists? input
contents = File.read input
end
end | ||
|
||
begin | ||
contents = JSON.parse(contents) |
akerl
Sep 1, 2014
Owner
Shadowing variables like this is frowned upon; variables are cheap, I might make them "raw" and "parsed" or similar
Shadowing variables like this is frowned upon; variables are cheap, I might make them "raw" and "parsed" or similar
params = { username: params } unless params.is_a? Hash | ||
@stats = GithubStats.new(params[:username]) | ||
params = { user: params } unless params.is_a? Hash | ||
@stats = params.fetch(:data) { GithubStats.new(params[:user]).data } |
akerl
Sep 1, 2014
Owner
I'm not 100% sure if I used attributes of GithubStats in the rest of this lib. If I did, you may need to do some cute magic now that it's a GithubStats::Data object.
I'm not 100% sure if I used attributes of GithubStats in the rest of this lib. If I did, you may need to do some cute magic now that it's a GithubStats::Data object.
Stantheman
Sep 1, 2014
Author
Contributor
I've tried to find where it happens, I'll take a second gander. So far in my flexing of it, I haven't seen it
I've tried to find where it happens, I'll take a second gander. So far in my flexing of it, I haven't seen it
Stantheman
Sep 1, 2014
Author
Contributor
Used in a test, coming up
edit: fixed the tests
Used in a test, coming up
edit: fixed the tests
…d collapsing long if check
…onsuming external data and checking for data creation without external data
Welcome to Ruby Club |
Add an option for file/STDIN to allow for third party chart data
This adds a -i/--input flag that takes a file or STDIN. In concert with something like fakehubstats, this would allow githubchart to create graphs of non-public or even non-git related streaks.
This is basically my first foray into Ruby, so I'm looking forward to feedback. I still need to add tests.