Skip to content

Commit

Permalink
#1 cli works
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Sep 29, 2014
1 parent 7509503 commit ed47569
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 8 deletions.
19 changes: 12 additions & 7 deletions bin/rultor
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ STDOUT.sync = true
require 'rultor'
require 'slop'
require 'rultor/version'
require 'rultor/encrypt'

opts = Slop.parse(ARGV, strict: true, help: true) do
Slop.parse(ARGV, strict: true, help: true) do
banner "Usage (#{Rultor::VERSION}): rultor command [options]"
end

if opts.help?
puts opts
else
puts 'not implemented yet'
on :v, 'Print the version' do
puts Rultor::VERSION
end
command 'encrypt' do
description 'Encrypt a file'
on :p=, :project, 'Project name'
run do |opts, args|
Rultor::Encrypt.new(opts[:project], args.first).run
end
end
end
3 changes: 3 additions & 0 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default: --format pretty
travis: --format progress
html_report: --format progress --format html --out=features_report.html
12 changes: 12 additions & 0 deletions features/cli/encrypt.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Command Line Processing
As an owner of a repository I want to have an
ability to encrypt my files

Scenario: Simple encrypting
Given I have a "credentials" file with content:
"""
some secret
"""
When I run bin/rultor with "encrypt -p test/test credentials"
Then Exit code is zero
And Stdout contains "encrypted credentials into credentials.asc"
8 changes: 8 additions & 0 deletions features/cli/help.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Help Banner
As an owner of a repository I want to have an
ability to read help

Scenario: Help can be printed
When I run bin/rultor with "-h"
Then Exit code is zero
And Stdout contains "Display this help message"
8 changes: 8 additions & 0 deletions features/cli/version.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Help Banner
As an owner of a repository I want to have an
ability to read help

Scenario: Help can be printed
When I run bin/rultor with "-v"
Then Exit code is zero
And Stdout contains "1.0.snapshot"
22 changes: 22 additions & 0 deletions features/gem_package.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: Gem Package
As a source code writer I want to be able to
package the Gem into .gem file

Scenario: Gem can be packaged
Given I have a "execs.rb" file with content:
"""
#!/usr/bin/env ruby
require 'rubygems'
spec = Gem::Specification::load('./spec.rb')
fail 'no executables' if spec.executables.empty?
"""
When I run bash with
"""
set -e
cd rultor
gem build rultor.gemspec
gem specification --ruby rultor-*.gem > ../spec.rb
cd ..
ruby execs.rb
"""
Then Exit code is zero
78 changes: 78 additions & 0 deletions features/step_definitions/steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# encoding: utf-8
#
# Copyright (c) 2009-2014, rultor.com
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met: 1) Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer. 2) Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution. 3) Neither the name of the rultor.com nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

require 'rultor'
require 'tmpdir'
require 'English'

Before do
@cwd = Dir.pwd
@dir = Dir.mktmpdir('test')
FileUtils.mkdir_p(@dir) unless File.exist?(@dir)
Dir.chdir(@dir)
end

After do
Dir.chdir(@cwd)
FileUtils.rm_rf(@dir) if File.exist?(@dir)
end

Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
File.open(file, 'w') do |f|
f.write(text)
end
end

When(/^I run bin\/rultor with "([^"]*)"$/) do |arg|
home = File.join(File.dirname(__FILE__), '../..')
@stdout = `ruby -I#{home}/lib #{home}/bin/rultor #{arg} 2>&1`
@exitstatus = $CHILD_STATUS.exitstatus
end

Then(/^Stdout contains "([^"]*)"$/) do |txt|
unless @stdout.include?(txt)
fail "STDOUT doesn't contain '#{txt}':\n#{@stdout}"
end
end

Then(/^Exit code is zero$/) do
fail "Non-zero exit code #{@exitstatus}:\n#{@stdout}" unless @exitstatus == 0
end

Then(/^Exit code is not zero$/) do
fail "Zero exit code:\n#{@stdout}" if @exitstatus == 0
end

When(/^I run bash with$/) do |text|
FileUtils.copy_entry(@cwd, File.join(@dir, 'rultor'))
@stdout = `#{text}`
@exitstatus = $CHILD_STATUS.exitstatus
end
34 changes: 34 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# encoding: utf-8
#
# Copyright (c) 2009-2014, rultor.com
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met: 1) Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer. 2) Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution. 3) Neither the name of the rultor.com nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

require 'simplecov'
require 'rultor'

Rultor.log = Logger.new(STDOUT)
46 changes: 46 additions & 0 deletions lib/rultor/encrypt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# encoding: utf-8
#
# Copyright (c) 2009-2014, rultor.com
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met: 1) Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer. 2) Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution. 3) Neither the name of the rultor.com nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

# Rultor main module.
# Author:: Yegor Bugayenko (yegor@teamed.io)
# Copyright:: Copyright (c) 2014 Yegor Bugayenko
# License:: BSD
module Rultor
class Encrypt
def initialize(name, file)
@name = name
@file = file
@dest = "#{@file}.asc"
end
def run
Rultor.log.info "encrypted #{@file} into #{@dest} for project #{@name}"
end
end
end
3 changes: 2 additions & 1 deletion rultor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ Gem::Specification.new do |s|
s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
s.test_files = s.files.grep(/^(test|spec|features)\//)
s.rdoc_options = ['--charset=UTF-8']
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
s.extra_rdoc_files = %w(README.md LICENSE.txt)
s.add_runtime_dependency 'rake', '~> 10.1'
s.add_runtime_dependency 'slop', '~> 3.6'
s.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7.0'
s.add_development_dependency 'rdoc', '~> 3.11'
s.add_development_dependency 'cucumber', '1.3.11'
Expand Down

0 comments on commit ed47569

Please sign in to comment.