This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
forked from dbresson/bedouin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for passing options to nomad
- Loading branch information
David Bresson
committed
Dec 9, 2020
1 parent
cfd08f2
commit 06177fb
Showing
8 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Bedouin | ||
class CLI | ||
class Params | ||
attr_reader :opts, :env_path, :template_paths | ||
def initialize(params) | ||
index_of_opt_terminator = params.find_index('--') | ||
unchecked_params = params.slice!((index_of_opt_terminator)..-1) if index_of_opt_terminator | ||
|
||
if args_count = params.reverse_each.find_index {|p| p.start_with? '-' } | ||
args, @opts = params.pop(args_count), params | ||
else | ||
args, @opts = params, [] | ||
end | ||
|
||
args.concat(unchecked_params.drop(1)) if unchecked_params | ||
|
||
@env_path, *@template_paths = *args | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Bedouin | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'spec_helper' | ||
require 'bedouin/cli/params' | ||
|
||
describe Bedouin::CLI::Params do | ||
[ | ||
{ | ||
params: %w(environment foo), | ||
expect: { | ||
opts: [], | ||
env_path: 'environment', | ||
template_paths: ['foo'] | ||
} | ||
}, | ||
{ | ||
params: %w(-- environment foo), | ||
expect: { | ||
opts: [], | ||
env_path: 'environment', | ||
template_paths: ['foo'] | ||
} | ||
}, | ||
{ | ||
params: %w(environment foo bar), | ||
expect: { | ||
opts: [], | ||
env_path: 'environment', | ||
template_paths: ['foo', 'bar'] | ||
} | ||
}, | ||
{ | ||
params: %w(-a -b -c environment foo bar), | ||
expect: { | ||
opts: ['-a', '-b', '-c'], | ||
env_path: 'environment', | ||
template_paths: ['foo', 'bar'] | ||
} | ||
}, | ||
{ | ||
params: %w(-a -b -c -- environment foo bar), | ||
expect: { | ||
opts: ['-a', '-b', '-c'], | ||
env_path: 'environment', | ||
template_paths: ['foo', 'bar'] | ||
} | ||
}, | ||
{ | ||
params: %w(-a -b -c -- -environment foo bar), | ||
expect: { | ||
opts: ['-a', '-b', '-c'], | ||
env_path: '-environment', | ||
template_paths: ['foo', 'bar'] | ||
} | ||
} | ||
].each do |c| | ||
context "for various parameter situations" do | ||
it "extracts cli parameters into opts, env_path, and template_paths" do | ||
p = Bedouin::CLI::Params.new(c[:params]) | ||
expect(p).to have_attributes(c[:expect]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters