-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli/puppetfile] Extract puppetfile actions
- Loading branch information
1 parent
27716f6
commit 3b8204d
Showing
5 changed files
with
156 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module R10K | ||
module Action | ||
module Puppetfile | ||
require 'r10k/action/puppetfile/cri_runner' | ||
require 'r10k/action/puppetfile/install' | ||
require 'r10k/action/puppetfile/check' | ||
require 'r10k/action/puppetfile/purge' | ||
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,41 @@ | ||
require 'r10k/puppetfile' | ||
require 'r10k/util/setopts' | ||
require 'r10k/errors/formatting' | ||
require 'r10k/logging' | ||
|
||
module R10K | ||
module Action | ||
module Puppetfile | ||
class Check | ||
include R10K::Logging | ||
include R10K::Util::Setopts | ||
|
||
def initialize(opts, argv) | ||
@opts = opts | ||
@argv = argv | ||
|
||
setopts(opts, { | ||
:root => :self, | ||
:moduledir => :self, | ||
:puppetfile => :path, | ||
:trace => :self, | ||
}) | ||
end | ||
|
||
def call | ||
pf = R10K::Puppetfile.new(@root, @moduledir, @path) | ||
|
||
begin | ||
pf.load | ||
$stderr.puts "Syntax OK" | ||
true | ||
rescue R10K::Error => e | ||
$stderr.puts R10K::Errors::Formatting.format_exception(e, @trace) | ||
false | ||
end | ||
end | ||
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,53 @@ | ||
require 'r10k/puppetfile' | ||
require 'r10k/util/setopts' | ||
require 'r10k/errors/formatting' | ||
require 'r10k/logging' | ||
|
||
module R10K | ||
module Action | ||
module Puppetfile | ||
class Install | ||
include R10K::Logging | ||
include R10K::Util::Setopts | ||
|
||
def initialize(opts, argv) | ||
@opts = opts | ||
@argv = argv | ||
|
||
@ok = true | ||
|
||
setopts(opts, { | ||
:root => :self, | ||
:moduledir => :self, | ||
:puppetfile => :path, | ||
:trace => :self, | ||
}) | ||
end | ||
|
||
def call | ||
pf = R10K::Puppetfile.new(@root, @moduledir, @path) | ||
pf.accept(self) | ||
@ok | ||
end | ||
|
||
def visit(type, other, &block) | ||
send("visit_#{type}", other, &block) | ||
rescue => e | ||
logger.error R10K::Errors::Formatting.format_exception(e, @trace) | ||
@ok = false | ||
end | ||
|
||
def visit_puppetfile(pf) | ||
pf.load | ||
yield | ||
pf.purge! | ||
end | ||
|
||
def visit_module(mod) | ||
logger.info "Updating module #{mod.path}" | ||
mod.sync | ||
end | ||
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,37 @@ | ||
require 'r10k/puppetfile' | ||
require 'r10k/util/setopts' | ||
require 'r10k/errors/formatting' | ||
require 'r10k/logging' | ||
|
||
module R10K | ||
module Action | ||
module Puppetfile | ||
class Purge | ||
include R10K::Logging | ||
include R10K::Util::Setopts | ||
|
||
def initialize(opts, argv) | ||
@opts = opts | ||
@argv = argv | ||
|
||
setopts(opts, { | ||
:root => :self, | ||
:moduledir => :self, | ||
:puppetfile => :path, | ||
:trace => :self, | ||
}) | ||
end | ||
|
||
def call | ||
pf = R10K::Puppetfile.new(@root, @moduledir, @path) | ||
pf.load | ||
pf.purge! | ||
true | ||
rescue => e | ||
logger.error R10K::Errors::Formatting.format_exception(e, opts[:trace]) | ||
false | ||
end | ||
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