yesman 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yesman.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jason Madsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ =======
2
+ # yesman
3
+ ======
4
+
5
+ Yesman is a ruby command line interface that creates basic directory structures for starting a C++ project. As a part of the creation of a new project Yesman will download, compile and generally get Google Test setup for the projects testing suite.
6
+
7
+ ## Installation
8
+
9
+ To install it simply run:
10
+
11
+ $ gem install yesman
12
+
13
+ ## Usage
14
+
15
+ To create a default project simply run:
16
+
17
+ $ yesman new ProjectName
18
+
19
+ Doing so will create a "ProjectName" directory with a "src", "tests", "bin" directory. GoogleTests will be compiled into a "gtest" directory inside of the "tests" directory. A main test runner file named "ProjectNameTests.cpp" will be created inside of the "tests" directory and a "ProjectName.cpp" file will be created in your "src" directory.
20
+
21
+ There are several optional parameters you can use that will adjust the following:
22
+
23
+ -s Source Directory Name (defaults to "src")
24
+
25
+ -t Tests Directory Name (defaults to "tests")
26
+
27
+ -o Output Directory Name (defaults to "bin")
28
+
29
+ -x C++ extension to use for generated files (defaults to "cpp")
30
+
31
+ ## Requirements
32
+
33
+ Under the hood there are several technologies that Yesman relies on. In order to run you will need the following:
34
+
35
+ G++ - You can get this by installing XCode on your mac, be sure to install the command line tools
36
+
37
+ svn - In order to pull down Google Test you will need to have svn installed on your machine
38
+
39
+ ruby > 1.9 - OS X is still shipping with 1.8.7. Use rvm to install the latest version of ruby
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/yesman ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yesman'
4
+ require 'yesman/cli_parser'
5
+
6
+ options = {}
7
+
8
+ command = ARGV.shift
9
+
10
+ def new_project
11
+ project_name = ARGV.shift
12
+ parser = CliParser.new
13
+ parser.run ARGV
14
+ parser.config[:project_name] = project_name
15
+ puts "Generating new project: #{parser.config[:project_name]}"
16
+ y = Yesman.new parser.config
17
+ end
18
+
19
+ def run_project
20
+ flag = ARGV.shift
21
+ if flag == '-d'
22
+ debug_project
23
+ else
24
+ puts "run not yet supported"
25
+ end
26
+ end
27
+
28
+ def debug_project
29
+ puts "debug (-d) not yet supported"
30
+ end
31
+
32
+ def test_project
33
+ puts "test not yet supported"
34
+ end
35
+
36
+
37
+ case command
38
+ when 'new'
39
+ new_project
40
+ when 'run'
41
+ run_project
42
+ when 'test'
43
+ test_project
44
+ else
45
+ puts "command: #{command} not recognized"
46
+ end
47
+
48
+
49
+
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'mixlib/cli'
3
+
4
+ class CliParser
5
+ include Mixlib::CLI
6
+
7
+ option :source,
8
+ :short => "-s SOURCE",
9
+ :long => "--source SOURCE",
10
+ :default => "src",
11
+ :description => "The name of the source directory to build"
12
+
13
+ option :tests,
14
+ :short => "-t TESTS",
15
+ :long => "--tests TESTS",
16
+ :default => "tests",
17
+ :description => "The name of the tests directory to build"
18
+
19
+ option :output,
20
+ :short => "-o OUTPUT",
21
+ :long => "--output OUTPUT",
22
+ :default => "bin",
23
+ :description => "The name of the output directory to build"
24
+
25
+ option :project_name,
26
+ :short => "-n NAME",
27
+ :long => "--name NAME",
28
+ :default => "Project",
29
+ :description =>"The name of the project to build"
30
+
31
+ option :debug,
32
+ :short => "-d DEBUG",
33
+ :long => "--debug DEBUG",
34
+ :boolean => true
35
+
36
+ option :extension,
37
+ :short => "-e EXTENSION",
38
+ :long => "--extension EXTENSION",
39
+ :default => "cpp",
40
+ :description => "Type of file extension to use for c++ files"
41
+
42
+ def run(argv=ARGV)
43
+ parse_options(argv)
44
+ end
45
+ end
@@ -0,0 +1,70 @@
1
+ require 'yesman/file_util'
2
+
3
+ class CppCreator
4
+ attr_reader :source
5
+ attr_reader :tests
6
+ attr_reader :output
7
+ attr_reader :project_name
8
+ attr_reader :extension
9
+
10
+ def initialize(params = {})
11
+ set_defaults params
12
+ end
13
+
14
+ def create_project
15
+ create_dirs
16
+ create_source_main
17
+ create_test_main
18
+ end
19
+
20
+ private
21
+
22
+ def set_defaults params
23
+ @source = params.fetch(:source){"src"}
24
+ @tests = params.fetch(:tests){"tests"}
25
+ @output = params.fetch(:output){"bin"}
26
+ @project_name = params.fetch(:project_name){"Project"}
27
+ @extension = params.fetch(:extension){"ccp"}
28
+ end
29
+
30
+ def create_dirs
31
+ FileUtil.ensure_path source
32
+ FileUtil.ensure_path tests
33
+ FileUtil.ensure_path output
34
+ end
35
+
36
+ def create_source_main
37
+ filename = "#{source}/#{project_name}.#{extension}"
38
+ FileUtil.ensure_file filename
39
+ FileUtil.write_to_file filename, get_source_main
40
+ end
41
+
42
+ def create_test_main
43
+ filename = "#{tests}/#{project_name}Tests.#{extension}"
44
+ FileUtil.ensure_file filename
45
+ FileUtil.write_to_file filename, get_test_main
46
+ end
47
+
48
+ def get_test_main
49
+ main = <<END
50
+ #include "gtest/gtest.h"
51
+
52
+ GTEST_API_ int main(int argc, char **argv) {
53
+ testing::InitGoogleTest(&argc, argv);
54
+ return RUN_ALL_TESTS();
55
+ }
56
+ END
57
+ end
58
+
59
+ def get_source_main
60
+ main = <<END
61
+ #include <iostream>
62
+
63
+ int main() {
64
+ std::cout << "What up world!" << std::endl;
65
+ return 0;
66
+ }
67
+
68
+ END
69
+ end
70
+ end
@@ -0,0 +1,58 @@
1
+ class FileUtil
2
+
3
+ def self.ensure_file path
4
+ dirs = self.determine_path path
5
+ filename = dirs.pop
6
+ self.create_directories dirs
7
+ self.verify_or_make_file path
8
+ end
9
+
10
+ def self.ensure_path path
11
+ dirs = self.determine_path path
12
+ self.create_directories dirs
13
+ end
14
+
15
+ def self.clear_directory path
16
+ self.kill_directory path
17
+ self.ensure_path path
18
+ end
19
+
20
+ def self.kill_directory path
21
+ `rm -rf #{path}` unless (!File.exists? path) || (!File.directory? path)
22
+ end
23
+
24
+ def self.kill_file filename
25
+ `rm #{filename}` unless !File.exists? filename
26
+ end
27
+
28
+ def self.recursive_copy from, to
29
+ `cp -r #{from} #{to}`
30
+ end
31
+
32
+ def self.write_to_file filename, contents
33
+ File.open( filename, "w" ) { |f| f.write( contents ) }
34
+ end
35
+ private
36
+
37
+ def self.create_directories dirs
38
+ next_path = ""
39
+ dirs.each do |dirname|
40
+ next_path << dirname << "/"
41
+ self.verify_or_make_dir next_path
42
+ end
43
+ end
44
+
45
+ def self.determine_path path
46
+ dirs = path.split("/")
47
+
48
+ end
49
+
50
+ def self.verify_or_make_dir dirname
51
+ `mkdir #{dirname}` unless (File.exists? dirname) && (File.directory? dirname)
52
+ end
53
+
54
+ def self.verify_or_make_file filename
55
+ `touch #{filename}` unless (File.exists? filename)
56
+ end
57
+
58
+ end
@@ -0,0 +1,74 @@
1
+ require 'yesman/file_util'
2
+
3
+ class GTestInstaller
4
+
5
+ attr_reader :gtest_local_repo_name
6
+ attr_reader :gtest_dir
7
+ attr_reader :gtest_path
8
+ attr_reader :attr_names
9
+ attr_reader :params
10
+
11
+ def initialize options
12
+ @params = options
13
+ @gtest_dir = "gtest"
14
+ @gtest_path = "http://googletest.googlecode.com/svn/trunk/"
15
+ @gtest_local_repo_name = "googletest-read-only"
16
+
17
+ end
18
+
19
+ def download_and_install
20
+ print_start
21
+ create_test_directories
22
+ pull_source
23
+ compile_source
24
+ create_static_lib
25
+ copy_needed_gtest_files
26
+ clean_up_dirs
27
+ end
28
+
29
+ private
30
+
31
+ def print_start
32
+ puts "********************************"
33
+ puts "** Google Test Setup **"
34
+ puts "********************************"
35
+ end
36
+
37
+ def pull_source
38
+ puts "checkout (svn) of GTest source code..."
39
+ `svn checkout #{gtest_path} #{repo_path}`
40
+ end
41
+
42
+ def compile_source
43
+ puts "compiling GTest source code..."
44
+ `g++ -I #{repo_path}/include/ -I #{repo_path}/ -c #{repo_path}/src/gtest-all.cc -o #{params[:tests]}/gtest/gtest-all.o`
45
+ end
46
+
47
+ def create_static_lib
48
+ puts "creating GTest static lib: 'libgtest.a'"
49
+ `ar -rv #{params[:tests]}/gtest/libgtest.a #{params[:tests]}/gtest/gtest-all.o`
50
+ end
51
+
52
+
53
+ def copy_needed_gtest_files
54
+ puts "copying needed GTest files to tests dir"
55
+ FileUtil.recursive_copy "#{repo_path}/include/gtest", "#{params[:tests]}/gtest/include"
56
+ end
57
+
58
+ def create_test_directories
59
+ FileUtil.clear_directory "#{params[:tests]}/gtest"
60
+ FileUtil.ensure_path "#{params[:tests]}/gtest/include"
61
+ end
62
+
63
+ def clean_up_dirs
64
+ puts "cleaning up our trash"
65
+ FileUtil.kill_directory gtest_dir
66
+ FileUtil.kill_file "#{params[:tests]}/gtest/gtest-all.o"
67
+ FileUtil.kill_directory "#{params[:tests]}/gtest/include/gtest/.svn"
68
+ end
69
+
70
+ def repo_path
71
+ "#{gtest_dir}/#{gtest_local_repo_name}"
72
+ end
73
+
74
+ end
@@ -0,0 +1,3 @@
1
+ module Yesman
2
+ VERSION = "0.0.2"
3
+ end
data/lib/yesman.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'yesman/cpp_creator'
2
+ require 'yesman/file_util'
3
+ require 'yesman/gtest_installer'
4
+
5
+ class Yesman
6
+ attr_reader :params
7
+
8
+ def initialize options = {}
9
+ create_defaults options
10
+ init
11
+ end
12
+
13
+ def create_defaults hash
14
+ @params = {}
15
+ @params[:project_name] = hash.fetch(:project_name){"Project"}
16
+ @params[:extension] = hash.fetch(:extension){"cpp"}
17
+ @params[:source] = hash.fetch(:source){"src"}
18
+ @params[:tests] = hash.fetch(:tests){"tests"}
19
+ @params[:output] = hash.fetch(:output){"bin"}
20
+ end
21
+
22
+ def init
23
+ FileUtil.ensure_path params[:project_name]
24
+ Dir.chdir( params[:project_name] )
25
+ create_all
26
+ end
27
+
28
+ def create_all
29
+ p = CppCreator.new params
30
+ p.create_project
31
+
32
+ g = GTestInstaller.new params
33
+ g.download_and_install
34
+ end
35
+
36
+ end
data/yesman.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yesman/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "yesman"
8
+ gem.version = Yesman::VERSION
9
+ gem.authors = ["Jason Madsen"]
10
+ gem.email = ["knomedia@gmail.com"]
11
+ gem.description = %q{CLI for quick creation of C++ projects using GTest}
12
+ gem.summary = %q{Yesman creates project directory structures, downloads and builds GTest for C++ development projects}
13
+ gem.homepage = ""
14
+
15
+ gem.add_dependency 'mixlib-cli'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yesman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Madsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mixlib-cli
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: CLI for quick creation of C++ projects using GTest
31
+ email:
32
+ - knomedia@gmail.com
33
+ executables:
34
+ - yesman
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/yesman
44
+ - lib/yesman.rb
45
+ - lib/yesman/cli_parser.rb
46
+ - lib/yesman/cpp_creator.rb
47
+ - lib/yesman/file_util.rb
48
+ - lib/yesman/gtest_installer.rb
49
+ - lib/yesman/version.rb
50
+ - yesman.gemspec
51
+ homepage: ''
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Yesman creates project directory structures, downloads and builds GTest for
75
+ C++ development projects
76
+ test_files: []