-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and add pupdb commandline prototype
- Loading branch information
mose
committed
Dec 4, 2015
1 parent
7b8e4dd
commit e5e910f
Showing
14 changed files
with
282 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$LOAD_PATH << File.expand_path("../../lib", __FILE__) | ||
|
||
require 'hieracles' | ||
|
||
opt = Hieracles::Options::Pupdb.new(ARGV) | ||
|
||
if opt.options.has_key? :version | ||
puts Hieracles.version | ||
exit(0) | ||
end | ||
|
||
command = opt.payload[0] | ||
args = opt.payload[2..-1] | ||
|
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,61 @@ | ||
module Hieracles | ||
module Options | ||
class Hc < Hieracles::Optparse | ||
|
||
def available_options | ||
{ | ||
config: { | ||
has_arg: true, | ||
aliases: ['c', 'conf', 'config'] | ||
}, | ||
format: { | ||
has_arg: true, | ||
aliases: ['f', 'format'] | ||
}, | ||
params: { | ||
has_arg: true, | ||
aliases: ['p', 'params'] | ||
}, | ||
hierafile: { | ||
has_arg: true, | ||
aliases: ['h', 'hierafile'] | ||
}, | ||
basepath: { | ||
has_arg: true, | ||
aliases: ['b', 'basepath'] | ||
}, | ||
encpath: { | ||
has_arg: true, | ||
aliases: ['e', 'encpath'] | ||
}, | ||
version: { | ||
has_arg: false, | ||
aliases: ['v', 'version'] | ||
}, | ||
yaml_facts: { | ||
has_arg: true, | ||
aliases: ['y', 'yaml'] | ||
}, | ||
json_facts: { | ||
has_arg: true, | ||
aliases: ['j', 'json'] | ||
}, | ||
interactive: { | ||
has_arg: false, | ||
aliases: ['i', 'interactive'] | ||
}, | ||
db: { | ||
has_arg: false, | ||
aliases: ['db'] | ||
}, | ||
nodb: { | ||
has_arg: false, | ||
aliases: ['nodb', 'no-db', 'no'] | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module Hieracles | ||
module Options | ||
class Pupdb < Hieracles::Optparse | ||
|
||
def available_options | ||
{ | ||
config: { | ||
has_arg: true, | ||
aliases: ['c', 'conf', 'config'] | ||
}, | ||
format: { | ||
has_arg: true, | ||
aliases: ['f', 'format'] | ||
}, | ||
params: { | ||
has_arg: true, | ||
aliases: ['p', 'params'] | ||
}, | ||
hierafile: { | ||
has_arg: true, | ||
aliases: ['h', 'hierafile'] | ||
}, | ||
basepath: { | ||
has_arg: true, | ||
aliases: ['b', 'basepath'] | ||
}, | ||
encpath: { | ||
has_arg: true, | ||
aliases: ['e', 'encpath'] | ||
}, | ||
version: { | ||
has_arg: false, | ||
aliases: ['v', 'version'] | ||
}, | ||
yaml_facts: { | ||
has_arg: true, | ||
aliases: ['y', 'yaml'] | ||
}, | ||
json_facts: { | ||
has_arg: true, | ||
aliases: ['j', 'json'] | ||
}, | ||
interactive: { | ||
has_arg: false, | ||
aliases: ['i', 'interactive'] | ||
}, | ||
db: { | ||
has_arg: false, | ||
aliases: ['db'] | ||
}, | ||
nodb: { | ||
has_arg: false, | ||
aliases: ['nodb', 'no-db', 'no'] | ||
} | ||
} | ||
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
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,19 @@ | ||
module Hieracles | ||
module Puppetdb | ||
class Request | ||
|
||
def initialize(client) | ||
@client = client | ||
end | ||
|
||
def info(fqdn) | ||
@client.request "nodes/#{fqdn}" | ||
end | ||
|
||
def facts(fqdn) | ||
@client.request "nodes/#{fqdn}/facts" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'spec_helper' | ||
|
||
describe Hieracles::Options::Hc do | ||
describe '.initialize' do | ||
context 'with proper arguments' do | ||
let(:array) { ['arg1', 'arg2', '-c', 'path/to/config-file', '-f', 'thatformat'] } | ||
let(:expected_payload) { ['arg1', 'arg2'] } | ||
let(:expected_options) do | ||
{ config: 'path/to/config-file', format: 'thatformat' } | ||
end | ||
subject { Hieracles::Options::Hc.new array } | ||
it "populates payload" do | ||
expect(subject.payload).to eq expected_payload | ||
end | ||
it 'populates options' do | ||
expect(subject.options).to eq expected_options | ||
end | ||
end | ||
|
||
context 'with proper arguments in random order' do | ||
let(:array) { ['-c', 'path/to/config-file', 'arg1', 'arg2', '-f', 'thatformat'] } | ||
let(:expected_payload) { ['arg1', 'arg2'] } | ||
let(:expected_options) do | ||
{ config: 'path/to/config-file', format: 'thatformat' } | ||
end | ||
subject { Hieracles::Options::Hc.new array } | ||
it "populates payload" do | ||
expect(subject.payload).to eq expected_payload | ||
end | ||
it 'populates options' do | ||
expect(subject.options).to eq expected_options | ||
end | ||
end | ||
|
||
context 'with funnily ordered arguments' do | ||
let(:array) { ['arg1', '-u', 'path/to/config-file', 'arg2', '-f', 'thatformat'] } | ||
let(:expected_payload) { ['arg1', 'arg2'] } | ||
let(:expected_options) do | ||
{ format: 'thatformat' } | ||
end | ||
subject { Hieracles::Options::Hc.new array } | ||
it "populates payload" do | ||
expect(subject.payload).to eq expected_payload | ||
end | ||
it 'populates options' do | ||
expect(subject.options).to eq expected_options | ||
end | ||
end | ||
|
||
context 'with arguments in alternative syntax' do | ||
let(:array) { ['arg1', 'arg2', '-config', 'path/to/config-file', '--format', 'thatformat'] } | ||
let(:expected_payload) { ['arg1', 'arg2'] } | ||
let(:expected_options) do | ||
{ config: 'path/to/config-file', format: 'thatformat' } | ||
end | ||
subject { Hieracles::Options::Hc.new array } | ||
it "populates payload" do | ||
expect(subject.payload).to eq expected_payload | ||
end | ||
it 'populates options' do | ||
expect(subject.options).to eq expected_options | ||
end | ||
end | ||
|
||
context 'with arguments containing boolean element' do | ||
let(:array) { ['arg1', 'arg2', '-i', '-format', 'thatformat'] } | ||
let(:expected_payload) { ['arg1', 'arg2'] } | ||
let(:expected_options) do | ||
{ format: 'thatformat', interactive: true } | ||
end | ||
subject { Hieracles::Options::Hc.new array } | ||
it "populates payload" do | ||
expect(subject.payload).to eq expected_payload | ||
end | ||
it 'populates options' do | ||
expect(subject.options).to eq expected_options | ||
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.