diff --git a/spec/mstrap/configuration_spec.cr b/spec/mstrap/configuration_spec.cr index 2bebec7..58b2f09 100644 --- a/spec/mstrap/configuration_spec.cr +++ b/spec/mstrap/configuration_spec.cr @@ -34,7 +34,7 @@ def delete_profile(name) end Spectator.describe MStrap::Configuration do - let(config_def) do + let(config_def_v1_0) do MStrap::Defs::ConfigDef.from_hcl(<<-HCL) version = "1.0" @@ -50,6 +50,8 @@ Spectator.describe MStrap::Configuration do HCL end + let(config_def) { config_def_v1_0 } + let(personal_profile_def) do MStrap::Defs::ProfileDef.from_hcl(<<-HCL) version = "1.0" @@ -315,6 +317,44 @@ Spectator.describe MStrap::Configuration do end end + describe "#runtime_manager" do + context "for v1.0 configs" do + subject { MStrap::Configuration.new(config_def_v1_0) } + + it "defaults to asdf" do + expect(subject.runtime_manager).to be_a(MStrap::RuntimeManagers::ASDF) + end + end + + context "for v1.1 configs" do + let(config_def_v1_1) do + MStrap::Defs::ConfigDef.from_hcl(<<-HCL) + version = "1.1" + + runtimes { + default_manager = "mise" + } + + user { + name = "Reginald Testington" + email = "reginald@testington.biz" + } + + profile "personal" { + url = "ssh://git@gitprovider.biz/reggiemctest/mstrap-personal.git" + } + + HCL + end + + subject { MStrap::Configuration.new(config_def_v1_1) } + + it "can be set through runtimes.default_manager" do + expect(subject.runtime_manager).to be_a(MStrap::RuntimeManagers::Mise) + end + end + end + describe "#save!" do it "saves the loaded configuration back to disk" do subject = MStrap::Configuration.new(config_def) diff --git a/src/mstrap/configuration.cr b/src/mstrap/configuration.cr index fdc22bc..b5e276b 100644 --- a/src/mstrap/configuration.cr +++ b/src/mstrap/configuration.cr @@ -44,7 +44,7 @@ module MStrap @loaded_profiles = [] of Defs::ProfileDef @known_profile_configs = config.profiles + [DEFAULT_PROFILE_CONFIG_DEF] @resolved_profile = Defs::ProfileDef.new - @runtime_manager = RuntimeManager.for(config.runtime_manager) + @runtime_manager = RuntimeManager.for(config.runtimes.default_manager) @user = User.new(user: config.user) end diff --git a/src/mstrap/defs/config_def.cr b/src/mstrap/defs/config_def.cr index 01cc90c..e473808 100644 --- a/src/mstrap/defs/config_def.cr +++ b/src/mstrap/defs/config_def.cr @@ -9,13 +9,13 @@ module MStrap @[HCL::Block(key: "profile")] property profiles = [] of ::MStrap::Defs::ProfileConfigDef - @[HCL::Attribute] - property runtime_manager = "asdf" + @[HCL::Block] + property runtimes = ::MStrap::Defs::RuntimesConfigDef.new @[HCL::Block] property user = ::MStrap::Defs::UserDef.new - def_equals_and_hash @version, @profiles, @user + def_equals_and_hash @version, @profiles, @runtimes, @user def self.from_url(url : String) HTTP::Client.get(url, tls: MStrap.tls_client) do |response| @@ -23,7 +23,11 @@ module MStrap end end - def initialize(@user = UserDef.new, @profiles = Array(ProfileConfigDef).new) + def initialize( + @user = UserDef.new, + @profiles = Array(ProfileConfigDef).new, + @runtimes = RuntimesConfigDef.new + ) end end end diff --git a/src/mstrap/defs/runtimes_config_def.cr b/src/mstrap/defs/runtimes_config_def.cr new file mode 100644 index 0000000..0df0c6e --- /dev/null +++ b/src/mstrap/defs/runtimes_config_def.cr @@ -0,0 +1,15 @@ +module MStrap + module Defs + class RuntimesConfigDef + include HCL::Serializable + + @[HCL::Attribute] + property default_manager = "asdf" + + def_equals_and_hash @default_manager + + def initialize + end + end + end +end diff --git a/src/mstrap/runtime_managers/mise.cr b/src/mstrap/runtime_managers/mise.cr index fe2c2b0..a94f5f2 100644 --- a/src/mstrap/runtime_managers/mise.cr +++ b/src/mstrap/runtime_managers/mise.cr @@ -18,7 +18,7 @@ module MStrap end cmd_args = ["exec"] + exec_args + ["--", command] - cmd_args += args unless !args + cmd_args += args if args if command && (!args || args.empty?) cmd "mise #{cmd_args.join(' ')}", quiet: true