gondler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af6a1eca7117b366e5bf8bec9c9ade7102151980
4
+ data.tar.gz: 2e32a5fef06eb0ed9e76be04d2c3c988d6683a4d
5
+ SHA512:
6
+ metadata.gz: 724ad049a3a375c23667c631c5a80ffa41d55020b59752fa5bc652a4026cdd026f6b0715dde08ab49cc5cd8f6f4938b0eab9e2ba867d109add3aebb421352eb9
7
+ data.tar.gz: c8cf63695aaf8f0e3b0c32ddac73de31867100b3863d65aaaf996a5fea8227eebd4215656e38b14f40d1f931ba56a17495484c0002f71d79639fd6ad652ef3f7
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .gondler
19
+ Gomfile
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`.
2
+ # The point is for the user to remove these configuration records
3
+ # one by one as the offences are removed from the code base.
4
+
5
+ Documentation:
6
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gondler.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rspec'
8
+ gem 'pry'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sho Kusano
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,68 @@
1
+ # Gondler
2
+
3
+ bundler for golang. inspired by [gom](https://github.com/mattn/gom).
4
+
5
+ ## Installation
6
+
7
+ $ gem install gondler
8
+
9
+ ## Usage
10
+
11
+ 1. Write your Gomfile
12
+
13
+ ```
14
+ gom 'github.com/golang/glog'
15
+ ```
16
+ 2. Install dependency packages: `gondler install`
17
+ 3. Build your application: `gondler build`
18
+ 4. Run tests: `gondler test`
19
+
20
+ ## Gomfile
21
+
22
+ like gom's Gomfile
23
+
24
+ ```ruby
25
+ gom 'github.com/golang/glog'
26
+ package 'github.com/golang/glog'
27
+
28
+ gom 'github.com/golang/glog', commit: 'c6f9652c7179652e2fd8ed7002330db089f4c9db'
29
+ gom 'github.com/golang/glog', branch: 'master'
30
+ gom 'github.com/golang/glog', tag: 'go1'
31
+
32
+ gom 'github.com/golang/glog', group: ['development', 'test']
33
+ group :development, :test do
34
+ gom 'github.com/golang/glog'
35
+ end
36
+
37
+ gom 'github.com/golang/glog', os: ['linux', 'darwin']
38
+ os :linux, :darwin do
39
+ gom 'github.com/golang/glog'
40
+ end
41
+ ```
42
+
43
+ ## Commands
44
+
45
+ build # Build with dependencies specified in your Gomfile
46
+ exec # Execute a command in the context of Gondler
47
+ help [COMMAND] # Describe available commands or one specific command
48
+ install # Install the dependecies specified in your Gomfile
49
+ list # Show all of the dependencies in the current bundle
50
+ repl # REPL in the context of Gondler
51
+ test # Test with dependencies specified in your Gomfile
52
+ version # Print Gondler version
53
+
54
+ ## Custom commands
55
+
56
+ Gondler supports custom commands.
57
+
58
+ 1. Create a executable script file somewhere in your executable paths. It must use the following naming schema `gondler-your-command`.
59
+ 2. This file can be written in any scripting language or binaries.
60
+ 3. Now your could use it as `gondler your-command`.
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/gondler ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gondler/cli'
4
+ Gondler::CLI.start
data/gondler.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gondler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gondler'
8
+ spec.version = Gondler::VERSION
9
+ spec.authors = ['Sho Kusano']
10
+ spec.email = ['rosylilly@aduca.org']
11
+ spec.description = %q{bundler for golang}
12
+ spec.summary = %q{bundler for golang}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_dependency 'thor', '~> 0.18.1'
23
+ end
@@ -0,0 +1,95 @@
1
+ require 'thor'
2
+ require 'readline'
3
+ require 'gondler'
4
+
5
+ module Gondler
6
+ class CLI < Thor
7
+ class_option :gomfile, type: :string, default: 'Gomfile'
8
+ class_option :path, type: :string, default: '.gondler'
9
+
10
+ def initialize(*args)
11
+ super
12
+
13
+ @gomfile = Gondler::Gomfile.new(options[:gomfile])
14
+
15
+ path = Pathname.new(options[:path])
16
+ path = Pathname.pwd + path unless path.absolute?
17
+ Gondler.env.path = path
18
+ ENV['PATH'] = "#{path + 'bin'}:#{ENV['PATH']}"
19
+ end
20
+
21
+ desc 'install', 'Install the dependecies specified in your Gomfile'
22
+ method_option :without, type: :array, default: []
23
+ def install
24
+ @gomfile.packages.each do |package|
25
+ puts "Install #{package}"
26
+ package.resolve
27
+ end
28
+ rescue Gondler::Package::InstallError => e
29
+ puts e.message
30
+ exit(1)
31
+ end
32
+
33
+ desc 'build', 'Build with dependencies specified in your Gomfile'
34
+ def build(*args)
35
+ invoke :exec, %w(go build) + args
36
+ end
37
+
38
+ desc 'test', 'Test with dependencies specified in your Gomfile'
39
+ def test(*args)
40
+ invoke :exec, %w(go test) + args
41
+ end
42
+
43
+ desc 'exec', 'Execute a command in the context of Gondler'
44
+ def exec(*args)
45
+ args.map! do |arg|
46
+ if arg.to_s.include?(' ')
47
+ %Q{"#{arg.gsub(/"/, '\"')}"}
48
+ else
49
+ arg
50
+ end
51
+ end
52
+ Kernel.exec(*args.join(' '))
53
+ end
54
+
55
+ desc 'list', 'Show all of the dependencies in the current bundle'
56
+ method_option :without, type: :array, default: []
57
+ def list
58
+ Gondler.withouts = options[:without]
59
+
60
+ puts 'Packages included by the gondler:'
61
+ @gomfile.packages.each do |package|
62
+ puts " * #{package}"
63
+ end
64
+ end
65
+
66
+ desc 'repl', 'REPL in the context of Gondler'
67
+ def repl
68
+ while buf = Readline.readline('> ', true)
69
+ Kernel.system(buf)
70
+ end
71
+ end
72
+
73
+ desc 'version', 'Print Gondler version'
74
+ def version
75
+ puts Gondler::VERSION
76
+ end
77
+
78
+ def method_missing(*args)
79
+ if executable?(args.first)
80
+ invoke(:exec, args)
81
+ elsif executable?("gondler-#{args.first}")
82
+ invoke(:exec, args)
83
+ else
84
+ STDERR.puts(%Q{Could not find command "#{args.first}"})
85
+ exit(1)
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def executable?(name)
92
+ system("hash #{name} 1> /dev/null 2>&1")
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,43 @@
1
+ module Gondler
2
+ class Env
3
+ class << self
4
+ def accessor(name, source)
5
+ define_method(name) do
6
+ @environments[source]
7
+ end
8
+
9
+ define_method("#{name}=") do |val|
10
+ val = val.to_s
11
+ ENV[source.to_s] = val
12
+ @environments[source] = val
13
+ end
14
+ end
15
+ end
16
+
17
+ def initialize
18
+ reload!
19
+ end
20
+
21
+ def reload!
22
+ @environments = {}
23
+ `go env`.each_line do |define|
24
+ matched = define.match(/\A([A-Z]+)="(.*)"\Z/)
25
+ @environments[matched[1].to_sym] = matched[2] if matched
26
+ end
27
+ end
28
+
29
+ accessor :arch, :GOARCH
30
+ accessor :bin, :GOBIN
31
+ accessor :char, :GOCHAR
32
+ accessor :exe, :GOEXE
33
+ accessor :host_arch, :GOHOSTARCH
34
+ accessor :host_os, :GOHOSTOS
35
+ accessor :os, :GOOS
36
+ accessor :path, :GOPATH
37
+ accessor :race, :GORACE
38
+ accessor :root, :GOROOT
39
+ accessor :tool_dir, :GOTOOLDIR
40
+ accessor :cc, :CC
41
+ accessor :gcc_flags, :GOGCCGLAGS
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ require 'gondler/package'
2
+
3
+ module Gondler
4
+ class Gomfile
5
+ def initialize(path)
6
+ @packages = []
7
+
8
+ load(path)
9
+ end
10
+ attr_reader :packages
11
+
12
+ def load(path)
13
+ instance_eval(File.read(path))
14
+ end
15
+
16
+ def gom(name, options = {})
17
+ options[:group] = @now_group if @now_group
18
+ options[:os] = @now_os if @now_os
19
+
20
+ package = Gondler::Package.new(name, options)
21
+ @packages.push(package) if package.installable?
22
+ end
23
+ alias_method :package, :gom
24
+
25
+ def group(*groups)
26
+ @now_group = groups
27
+ yield if block_given?
28
+ ensure
29
+ @now_group = nil
30
+ end
31
+
32
+ def os(*oss)
33
+ @now_os = oss
34
+ yield if block_given?
35
+ ensure
36
+ @now_os = nil
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,111 @@
1
+ require 'English'
2
+
3
+ module Gondler
4
+ class Package
5
+ class InstallError < StandardError
6
+ end
7
+
8
+ def initialize(name, options = {})
9
+ @name = name
10
+ @branch = options[:branch]
11
+ @tag = options[:tag]
12
+ @commit = options[:commit]
13
+ @os = options[:os]
14
+ @group = options[:group]
15
+ @fix = options[:fix] || false
16
+ @flag = options[:flag]
17
+ end
18
+
19
+ def os
20
+ case @os
21
+ when String
22
+ @os.split(/\s+/)
23
+ when Array
24
+ @os.map(&:to_s).map(&:strip)
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def group
31
+ case @group
32
+ when String
33
+ @group.split(/\s+/)
34
+ when Array
35
+ @group.map(&:to_s).map(&:strip)
36
+ else
37
+ []
38
+ end
39
+ end
40
+
41
+ def target
42
+ @commit || @branch || @tag
43
+ end
44
+
45
+ def installable?
46
+ (
47
+ (os.nil? || os.include?(Gondler.env.os)) &&
48
+ (group.empty? || (Gondler.withouts & group).empty?)
49
+ )
50
+ end
51
+
52
+ def resolve
53
+ get
54
+ checkout if target
55
+ install
56
+ end
57
+
58
+ def get
59
+ args = %w(go get -d)
60
+ args << '-fix' if @fix
61
+ args << @name
62
+
63
+ result = `#{args.join(' ')} 2>&1`
64
+
65
+ unless $CHILD_STATUS.success?
66
+ raise InstallError.new("#{@name} download error\n" + result)
67
+ end
68
+ end
69
+
70
+ def checkout
71
+ src_path = Pathname.new(Gondler.env.path) + 'src'
72
+ @name.split('/').reduce(src_path) do |path, dir|
73
+ path += dir
74
+ if File.directory?(path + '.git')
75
+ break checkout_with_git(path)
76
+ elsif File.directory?(path + '.hg')
77
+ break checkout_with_hg(path)
78
+ end
79
+ path
80
+ end
81
+ end
82
+
83
+ def checkout_with_git(path)
84
+ Dir.chdir(path) do
85
+ `git checkout -q #{target}`
86
+ end
87
+ end
88
+
89
+ def checkout_with_hg(path)
90
+ Dir.chdir(path) do
91
+ `hg update #{target}`
92
+ end
93
+ end
94
+
95
+ def install
96
+ args = %w(go install)
97
+ args << @flag if @flag
98
+ args << @name
99
+
100
+ result = `#{args.join(' ')} 2>&1`
101
+
102
+ unless $CHILD_STATUS.success?
103
+ raise InstallError.new("#{@name} install error\n" + result)
104
+ end
105
+ end
106
+
107
+ def to_s
108
+ "#{@name}" + (target ? " (#{target})" : '')
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ module Gondler
2
+ VERSION = '0.0.1'
3
+ end
data/lib/gondler.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'open3'
2
+ require 'gondler/version'
3
+ require 'gondler/env'
4
+ require 'gondler/package'
5
+ require 'gondler/gomfile'
6
+
7
+ module Gondler
8
+ class << self
9
+ def withouts
10
+ @withouts || []
11
+ end
12
+
13
+ def withouts=(withouts)
14
+ @withouts = withouts.map(&:strip)
15
+ end
16
+
17
+ def env
18
+ @env ||= Gondler::Env.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gondler::Env do
4
+ let(:env) { described_class.new }
5
+
6
+ describe '#os' do
7
+ subject { env.os }
8
+
9
+ it { should == `go env GOOS`.strip }
10
+ end
11
+
12
+ describe '#path=' do
13
+ it 'should override path environment' do
14
+ env.path = 'spec'
15
+ env.reload!
16
+ expect(env.path).to eq('spec')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe Gondler::Gomfile do
5
+ let(:gomfile) { described_class.new(path) }
6
+ let(:file) do
7
+ Tempfile.open('Gomfile').tap do|f|
8
+ f.print(content)
9
+ f.flush
10
+ end
11
+ end
12
+ let(:path) { file.path }
13
+ let(:content) { '' }
14
+ after { file.close! }
15
+
16
+ describe '#gom' do
17
+ let(:content) do
18
+ <<-CONTENT
19
+ gom 'github.com/golang/glog'
20
+ CONTENT
21
+ end
22
+
23
+ it 'packages should include glog' do
24
+ expect(gomfile.packages).to have(1).package
25
+ end
26
+ end
27
+
28
+ describe '#group' do
29
+ let(:content) do
30
+ <<-CONTENT
31
+ group :development, :test do
32
+ gom 'github.com/golang/glog'
33
+ end
34
+ CONTENT
35
+ end
36
+
37
+ it 'package group should == development and test' do
38
+ expect(gomfile.packages.first.group).to eq(%w(development test))
39
+ end
40
+ end
41
+
42
+ describe '#os' do
43
+ let(:content) do
44
+ <<-CONTENT
45
+ os :darwin, :linux do
46
+ gom 'github.com/golang/glog'
47
+ end
48
+ CONTENT
49
+ end
50
+
51
+ it 'package os should == darwin and linux' do
52
+ expect(gomfile.packages.first.os).to eq(%w(darwin linux))
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gondler::Package do
4
+ let(:name) { 'github.com/golang/glog' }
5
+ let(:options) { {} }
6
+ let(:package) { described_class.new(name, options) }
7
+
8
+ describe '#os' do
9
+ let(:expected) { %w(linux darwin) }
10
+ subject { package.os }
11
+
12
+ context 'with ["linux", "darwin"]' do
13
+ let(:options) { { os: %w(linux darwin) } }
14
+
15
+ it { should == expected }
16
+ end
17
+
18
+ context 'with "linux darwin"' do
19
+ let(:options) { { os: 'linux darwin' } }
20
+
21
+ it { should == expected }
22
+ end
23
+ end
24
+
25
+ describe '#installable?' do
26
+ before { Gondler.env.os = 'darwin' }
27
+ after { Gondler.env.reload! }
28
+
29
+ subject { package.installable? }
30
+
31
+ context 'when os option is nil' do
32
+ it { should be_true }
33
+ end
34
+
35
+ context 'when os option is darwin' do
36
+ let(:options) { { os: 'darwin' } }
37
+
38
+ it { should be_true }
39
+ end
40
+
41
+ context 'when os option is linux' do
42
+ let(:options) { { os: 'linux' } }
43
+
44
+ it { should be_false }
45
+ end
46
+
47
+ context 'when os option is linux and darwin' do
48
+ let(:options) { { os: 'linux darwin' } }
49
+
50
+ it { should be_true }
51
+ end
52
+
53
+ context 'when development without' do
54
+ before { Gondler.withouts = %w(development) }
55
+ after { Gondler.withouts = [] }
56
+
57
+ let(:options) { { group: 'development' } }
58
+
59
+ it { should be_false }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gondler do
4
+ describe '.env' do
5
+ subject { Gondler.env }
6
+
7
+ it { should be_kind_of(Gondler::Env) }
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'gondler'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gondler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sho Kusano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.18.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.18.1
41
+ description: bundler for golang
42
+ email:
43
+ - rosylilly@aduca.org
44
+ executables:
45
+ - gondler
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - .rspec
51
+ - .rubocop.yml
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/gondler
57
+ - gondler.gemspec
58
+ - lib/gondler.rb
59
+ - lib/gondler/cli.rb
60
+ - lib/gondler/env.rb
61
+ - lib/gondler/gomfile.rb
62
+ - lib/gondler/package.rb
63
+ - lib/gondler/version.rb
64
+ - spec/gondler/env_spec.rb
65
+ - spec/gondler/gomfile_spec.rb
66
+ - spec/gondler/package_spec.rb
67
+ - spec/gondler_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: ''
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: bundler for golang
93
+ test_files:
94
+ - spec/gondler/env_spec.rb
95
+ - spec/gondler/gomfile_spec.rb
96
+ - spec/gondler/package_spec.rb
97
+ - spec/gondler_spec.rb
98
+ - spec/spec_helper.rb