Skip to content

Commit

Permalink
Create runtimes config section for default_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierke committed Jan 28, 2024
1 parent 2475104 commit c6ffdee
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
42 changes: 41 additions & 1 deletion spec/mstrap/configuration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/mstrap/configuration.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions src/mstrap/defs/config_def.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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

0 comments on commit c6ffdee

Please sign in to comment.