Skip to content

Commit

Permalink
Create runtimes config section for default_manager
Browse files Browse the repository at this point in the history
maxfierke committed Jan 28, 2024
1 parent 25d0c23 commit 2b8571a
Showing 5 changed files with 66 additions and 7 deletions.
42 changes: 41 additions & 1 deletion spec/mstrap/configuration_spec.cr
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
}
profile "personal" {
url = "ssh://[email protected]/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)
2 changes: 1 addition & 1 deletion src/mstrap/configuration.cr
Original file line number Diff line number Diff line change
@@ -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

12 changes: 8 additions & 4 deletions src/mstrap/defs/config_def.cr
Original file line number Diff line number Diff line change
@@ -9,21 +9,25 @@ 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|
self.from_hcl(response.body_io.gets_to_end)
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
15 changes: 15 additions & 0 deletions src/mstrap/defs/runtimes_config_def.cr
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/mstrap/runtime_managers/mise.cr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2b8571a

Please sign in to comment.