Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default config command #67

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/gel/command/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

class Gel::Command::Config < Gel::Command
def run(command_line)
if command_line.size == 1
if command_line.empty?
Gel::Environment.config.all.each do |key,_|
value = Gel::Environment.config[key]
puts "#{key}=#{value}"
end
elsif command_line.size == 1
puts Gel::Environment.config[command_line.first]
else
Gel::Environment.config[command_line.shift] = command_line.join(" ")
Expand Down
6 changes: 5 additions & 1 deletion lib/gel/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Gel::Config
def initialize
@root = File.expand_path("~/.config/gel")
@root = ENV.fetch('GEL_CONFIG') { File.expand_path("~/.config/gel") }
@path = File.join(@root, "config")
@config = nil
end
Expand All @@ -11,6 +11,10 @@ def config
@config ||= read
end

def all
config
end

def [](group = nil, key)
if group.nil?
group, key = key.split(".", 2)
Expand Down
Empty file added test/config/gel/config
Empty file.
23 changes: 23 additions & 0 deletions test/config_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "test_helper"

class ConfigTest < Minitest::Test
def test_reading_single_item_from_config_successully
prev_gel_config = ENV['GEL_CONFIG']
ENV['GEL_CONFIG'] = fixture_file('')
klass = Gel::Config.new
assert_equal '1', klass['jobs']
assert_equal 'true', klass['gem.mit']
ENV['GEL_CONFIG'] = prev_gel_config
end

def test_reading_all_from_config_successully
prev_gel_config = ENV['GEL_CONFIG']
ENV['GEL_CONFIG'] = fixture_file('')
output = Gel::Config.new.all
assert output['jobs'] == { '' => '1' }
assert output['gem'] == { 'mit' => 'true' }
ENV['GEL_CONFIG'] = prev_gel_config
end
end
4 changes: 4 additions & 0 deletions test/fixtures/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jobs:
: 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops... (while jobs isn't a valid config setting anyway,) this isn't supposed to look like that.

I think this:

group, key = key.split(".", 2)

needs to be followed by something like:

group, key = nil, group if key.nil?

On the other hand, maybe we should change the file format (or group/key format?) to something different. The current behaviour looks not-great when key is a DNS name, as #73's example shows for packages.shopify.io. But that's a thought for another day.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With bundle config local.GEM_NAME /path/to/local/git/repository and bundle config jobs 5 we get the output:

.bundle % cat config
---
BUNDLE_GEM__TEST: "minitest"
BUNDLE_JOBS: "7"
BUNDLE_LOCAL__GEM_NAME: "/path/to/local/git/repository"

To be honest bundlers output is not great either - WDYT? I'm going to give this a little more thought.

gem:
mit: true