Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from boxen/chgo-yo
Browse files Browse the repository at this point in the history
switch to chgo over goenv
  • Loading branch information
wfarr committed Nov 2, 2013
2 parents 80e3325 + 953a485 commit b3226a2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 42 deletions.
2 changes: 1 addition & 1 deletion manifests/global.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$klass = join(['go', join(split($version, '[.]'), '_')], '::')
require $klass

file { "${go::goenv_root}/version":
file { "${go::chgo_root}/version":
content => "${version}\n",
replace => true,
}
Expand Down
39 changes: 28 additions & 11 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Public: Install GoEnv
# Public: Install chgo

class go(
$goenv_root = $go::params::goenv_root,
$goenv_user = $go::params::goenv_user,
$goenv_version = $go::params::goenv_version,
$chgo_root = $go::params::chgo_root,
$chgo_user = $go::params::chgo_user,
$chgo_version = $go::params::chgo_version,
$auto_switch = $go::params::auto_switch,

$goenv_root = $go::params::goenv_root,
) inherits go::params {
if $::osfamily == 'Darwin'{
include homebrew
Expand All @@ -16,16 +19,30 @@
ensure => absent,
}

boxen::env_script { 'go':
content => template('go/goenv.sh.erb'),
priority => 'higher',
$chgo_auto_ensure = $auto_switch ? {
true => present,
default => absent,
}

boxen::env_script {
'go':
content => template('go/env.sh.erb'),
priority => 'higher' ;
'chgo_auto':
ensure => $chgo_auto_ensure,
content => "source \$CHGO_ROOT/share/chgo/auto.sh\n",
priority => 99 ;
}
}

repository { $goenv_root:
ensure => $goenv_version,
repository { $chgo_root:
ensure => $chgo_version,
force => true,
source => 'wfarr/goenv',
user => $goenv_user,
source => 'wfarr/chgo',
user => $chgo_user,
}

repository { $goenv_root:
ensure => absent,
}
}
4 changes: 2 additions & 2 deletions manifests/local.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set a directory's default go version via goenv.
# Automatically ensures that go version is installed via goenv.
# Set a directory's default go version via chgo.
# Automatically ensures that go version is installed via chgo.
#
# Usage:
#
Expand Down
10 changes: 7 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
Darwin: {
include boxen::config

$goenv_user = $::boxen_user
$chgo_user = $::boxen_user
$chgo_root = "${boxen::config::home}/chgo"
$goenv_root = "${boxen::config::home}/goenv"
}

default: {
$goenv_user = 'root'
$chgo_user = 'root'
$chgo_root = '/usr/local/share/chgo'
$goenv_root = '/usr/local/share/goenv'
}
}

$goenv_version = 'v0.0.3'
$auto_switch = true

$chgo_version = 'v0.1.1'
}
14 changes: 7 additions & 7 deletions manifests/version.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Public: Install a Go version with goenv
# Public: Install a Go version with chgo
#
# Usage: go::version { '1.2.3': }

Expand All @@ -8,23 +8,23 @@
validate_re($ensure, '^(present|absent)$',
"Go::Version[${name}] ensure must be present|absent, is ${ensure}")

$dest = "${go::goenv_root}/versions/${name}"
$dest = "${go::chgo_root}/versions/${name}"

if $ensure == absent {
file { $dest:
ensure => absent,
force => true,
}
} else {
exec { "goenv install ${name}":
command => "${go::goenv_root}/bin/goenv install ${name}",
exec { "chgo install ${name}":
command => "source ${go::chgo_root}/share/chgo/chgo.sh && chgo_install ${name}",
creates => $dest,
provider => shell,
user => $go::goenv_user
user => $go::chgo_user
}

Exec["goenv install ${name}"] {
environment +> "GOENV_ROOT=${go::goenv_root}"
Exec["chgo install ${name}"] {
environment +> "CHGO_ROOT=${go::chgo_root}"
}
}
}
2 changes: 1 addition & 1 deletion spec/classes/go__global_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
should include_class("go")
should include_class("go::1_1_1")

should contain_file("/test/boxen/goenv/version").with({
should contain_file("/test/boxen/chgo/version").with({
:content => "1.1.1\n",
})
end
Expand Down
9 changes: 3 additions & 6 deletions spec/classes/go_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

it do
should include_class("boxen::config")
should contain_package("go").with_ensure(:absent)

should contain_file("/test/boxen/env.d/goenv.sh").with({
:ensure => "absent"
})

should contain_boxen__env_script("go")

should contain_repository("/test/boxen/goenv").with({
:ensure => "v0.0.3",
:source => "wfarr/goenv",
should contain_repository("/test/boxen/chgo").with({
:ensure => "v0.1.0",
:source => "wfarr/chgo",
:user => "testuser"
})
end
Expand All @@ -25,7 +23,6 @@

it do
should_not include_class("boxen::config")
should_not contain_package("go").with_ensure(:absent)
end
end
end
8 changes: 4 additions & 4 deletions spec/defines/go__version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
it do
should include_class("go")

should contain_exec("goenv install 1.2.3").with({
:command => "/test/boxen/goenv/bin/goenv install 1.2.3",
:creates => "/test/boxen/goenv/versions/1.2.3",
should contain_exec("chgo install 1.2.3").with({
:command => "source /test/boxen/chgo/share/chgo/chgo.sh && chgo install 1.2.3",
:creates => "/test/boxen/chgo/versions/1.2.3",
:provider => "shell",
:user => "testuser"
})
Expand All @@ -25,7 +25,7 @@
let(:params) { default_params.merge(:ensure => "absent") }

it do
should contain_file("/test/boxen/goenv/versions/1.2.3").with({
should contain_file("/test/boxen/chgo/versions/1.2.3").with({
:ensure => "absent",
:force => true
})
Expand Down
3 changes: 3 additions & 0 deletions templates/env.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Configure and activate chgo. You know, for go.

source <%= @chgo_root %>/share/chgo/chgo.sh
7 changes: 0 additions & 7 deletions templates/goenv.sh.erb

This file was deleted.

0 comments on commit b3226a2

Please sign in to comment.