Skip to content

Commit

Permalink
use command line flags [#101447714]
Browse files Browse the repository at this point in the history
Signed-off-by: JT Archie <[email protected]>
  • Loading branch information
Amin Jams authored and jtarchie committed Sep 3, 2015
1 parent 7232133 commit 845b80c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ To run `binary-builder` from within the cflinuxfs2 rootfs, use [Docker](https://

```bash
docker run -w /binary-builder -v `pwd`:/binary-builder -it cloudfoundry/cflinuxfs2 bash
./bin/binary-builder [binary_name] [binary_version] [checksum_value(MD5|SHA256)]
./bin/binary-builder --name=[binary_name] --version=[binary_version] --checksum=[checksum_value(MD5|SHA256)]
```

This generates a gzipped tarball in the binary-builder directory with the filename format `binary_name-binary_version-linux-x64`.

For example, if you were building nginx 1.7.11, you'd run the following commands:
For example, if you were building ruby 2.2.3, you'd run the following commands:

```bash
$ docker run -w /binary-builder -v `pwd`:/binary-builder -it cloudfoundry/cflinuxfs2 ./bin/binary-builder ruby 2.2.3 150a5efc5f5d8a8011f30aa2594a7654
$ docker run -w /binary-builder -v `pwd`:/binary-builder -it cloudfoundry/cflinuxfs2 ./bin/binary-builder --name=ruby --version=2.2.3 --checksum=150a5efc5f5d8a8011f30aa2594a7654
$ ls
ruby-2.2.3-linux-x64.tgz
```
Expand Down
26 changes: 16 additions & 10 deletions bin/binary-builder
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'builder'
require 'optparse'

USAGE_MESSAGE = "USAGE: binary-builder [binary name] [binary version] [checksum value]"

# e.g. node 0.12.7 md5-value (SHA/PGP/MD5)
unless ARGV[0] && ARGV[1] && ARGV[2]
puts USAGE_MESSAGE
exit 1
options = {}
optparser = OptionParser.new do |opts|
opts.banner = "USAGE: binary-builder [options]"

opts.on("-nNAME","--name=NAME", "Name of the binary e.g. nginx",:REQUIRED) do |n|
options[:binary_name] = n
end
opts.on( "-vVERSION","--version=VERSION", "Version of the binary e.g. 1.7.11",:REQUIRED) do |n|
options[:binary_version] = n
end
opts.on("-cCHECKSUM","--checksum=CHECKSUM", "Checksum of the binary e.g. abc123",:REQUIRED) do |n|
options[:checksum_value] = n
end
end
optparser.parse!

options = {
binary_name: ARGV[0],
binary_version: ARGV[1],
checksum_value: ARGV[2]
}
raise optparser.help unless options.keys.sort == [:binary_name, :binary_version, :checksum_value]

BinaryBuilder::Builder.build(options)
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run(cmd, log = false)
end

def run_binary_builder(binary_name, binary_version, checksum)
binary_builder_cmd = "#{File.join('./bin', 'binary-builder')} #{binary_name} #{binary_version} #{checksum}"
binary_builder_cmd = "#{File.join('./bin', 'binary-builder')} --name #{binary_name} --version #{binary_version} --checksum #{checksum}"
run(binary_builder_cmd, true)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/binary_builder_script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module BinaryBuilder
describe 'binary-builder script' do
context 'without valid arguments' do
it 'prints out a helpful usage message if no arguments are provided' do
expect(`#{File.join('./bin', 'binary-builder')}`).to include('USAGE', 'binary')
expect(`#{File.join('./bin', 'binary-builder')} 2>&1`).to include('USAGE', 'binary')
end
end
end
Expand Down

0 comments on commit 845b80c

Please sign in to comment.