Skip to content

Commit

Permalink
#2 slop 4
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 15, 2017
1 parent bac04a2 commit df0a3ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 55 deletions.
60 changes: 16 additions & 44 deletions bin/tdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,17 @@ require 'tdx'

args = ARGV

opts = Slop.parse(args, strict: true, help: true) do
banner "Usage (#{TDX::VERSION}): tdx [options]"
on('version', 'Show current version')
on(
'r',
'repo',
'Repository URI, e.g. "git@github.com:yegor256/tdx.git"',
type: String,
argument: :required,
limit: 1
)
on(
'tests',
opts = Slop.parse(args, strict: true, help: true) do |o|
o.banner = "Usage (#{TDX::VERSION}): tdx [options] <GitHub URI> <SVG path>"
o.bool '-h', '--help', 'Show usage summary'
o.bool '-v', '--version', 'Show current version'
o.array(
'--tests',
'Comma-separated list of relative paths with test-related files',
type: String,
argument: :required,
limit: 1
)
on(
'login',
'GitHub login',
argument: :required,
type: String,
limit: 1
)
on(
'password',
'GitHub password',
argument: :required,
type: String,
limit: 1
)
on(
's',
'svg',
'Full path of the SVG file to generate (STDOUT otherwise)',
argument: :required,
type: String,
limit: 1
delimiter: ','
)
o.string '--login', 'GitHub login'
o.string '--password', 'GitHub password'
end

if opts.help?
Expand All @@ -80,11 +51,12 @@ if opts.version?
exit
end

if opts.arguments.length < 2
puts 'URI and SVG path are required'
exit
end

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
output = TDX::Base.new(opts).svg
if opts[:svg]
File.new(opts[:svg], 'w') << output
else
puts output
end
output = TDX::Base.new(opts.arguments[0], opts).svg
File.new(opts.arguments[1], 'w') << output
2 changes: 1 addition & 1 deletion features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Command Line Processing

Scenario: Simple SVG is built
Given I have a Git repository in ./repo
When I run bin/tdx with "--svg pic.svg --repo file://$(pwd)/repo"
When I run bin/tdx with "file://$(pwd)/repo pic.svg"
Then Stdout is empty
Then Exit code is zero
And SVG is valid in "pic.svg"
Expand Down
5 changes: 3 additions & 2 deletions lib/tdx/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
module TDX
# Base class
class Base
def initialize(opts)
def initialize(uri, opts)
@uri = uri
@opts = opts
end

Expand Down Expand Up @@ -79,7 +80,7 @@ def svg

def checkout
dir = Dir.mktmpdir
`cd #{dir} && git clone --quiet #{@opts[:repo]} .`
`cd #{dir} && git clone --quiet #{@uri} .`
dir
end

Expand Down
2 changes: 1 addition & 1 deletion tdx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Gem::Specification.new do |s|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.rdoc_options = ['--charset=UTF-8']
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
s.add_runtime_dependency 'slop', '~>3.6'
s.add_runtime_dependency 'slop', '~>4.4.1'
s.add_development_dependency 'rake', '12.0.0'
s.add_development_dependency 'cucumber', '1.3.17'
s.add_development_dependency 'coveralls', '0.7.2'
Expand Down
14 changes: 7 additions & 7 deletions test/test_tdx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_git_repo
Dir.mktmpdir 'test' do |dir|
opts = opts(
[
'--repo', "file:///#{File.join(dir, 'repo')}",
'--tests', 'tests'
]
)
Expand All @@ -51,18 +50,19 @@ def test_git_repo
mkdir tests
echo 'c = 3' > tests/3.py && git add tests/3.py && git commit -qam '3'
")
assert(TDX::Base.new(opts).svg.include?('<path '))
assert(
TDX::Base.new(
"file:///#{File.join(dir, 'repo')}", opts
).svg.include?('<path ')
)
end
end

private

def opts(args)
Slop.parse args do
on 'p', 'path', argument: :required
on 's', 'svg', argument: :required
on 'r', 'repo', argument: :required
on 't', 'tests', argument: :required
Slop.parse args do |o|
o.string '-t', '--tests', argument: :required
end
end
end

0 comments on commit df0a3ce

Please sign in to comment.