diff --git a/manifests/global.pp b/manifests/global.pp index 0209ff7..5c9b738 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -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, } diff --git a/manifests/init.pp b/manifests/init.pp index c4517ae..4f4b969 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ -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, } } diff --git a/manifests/local.pp b/manifests/local.pp index 6b2b26d..0f71d6c 100644 --- a/manifests/local.pp +++ b/manifests/local.pp @@ -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: # diff --git a/manifests/params.pp b/manifests/params.pp index 2c10079..9e78220 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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' } diff --git a/manifests/version.pp b/manifests/version.pp index 8df5bd3..75925fa 100644 --- a/manifests/version.pp +++ b/manifests/version.pp @@ -1,4 +1,4 @@ -# Public: Install a Go version with goenv +# Public: Install a Go version with chgo # # Usage: go::version { '1.2.3': } @@ -8,7 +8,7 @@ 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: @@ -16,15 +16,15 @@ 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}" } } } diff --git a/spec/classes/go__global_spec.rb b/spec/classes/go__global_spec.rb index 9dce9c9..d5d67cb 100644 --- a/spec/classes/go__global_spec.rb +++ b/spec/classes/go__global_spec.rb @@ -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 diff --git a/spec/classes/go_spec.rb b/spec/classes/go_spec.rb index a3296fd..1f510c9 100644 --- a/spec/classes/go_spec.rb +++ b/spec/classes/go_spec.rb @@ -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 @@ -25,7 +23,6 @@ it do should_not include_class("boxen::config") - should_not contain_package("go").with_ensure(:absent) end end end diff --git a/spec/defines/go__version_spec.rb b/spec/defines/go__version_spec.rb index 4b5fda7..b19dde4 100644 --- a/spec/defines/go__version_spec.rb +++ b/spec/defines/go__version_spec.rb @@ -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" }) @@ -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 }) diff --git a/templates/env.sh.erb b/templates/env.sh.erb new file mode 100644 index 0000000..e707430 --- /dev/null +++ b/templates/env.sh.erb @@ -0,0 +1,3 @@ +# Configure and activate chgo. You know, for go. + +source <%= @chgo_root %>/share/chgo/chgo.sh diff --git a/templates/goenv.sh.erb b/templates/goenv.sh.erb deleted file mode 100644 index 8656878..0000000 --- a/templates/goenv.sh.erb +++ /dev/null @@ -1,7 +0,0 @@ -# Configure and activate goenv. You know, for go. - -export GOENV_ROOT=<%= @goenv_root %> - -export PATH=<%= @goenv_root %>/bin:$PATH - -eval "$(goenv init -)"