-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from marianitadn/add-command-to-add-new-resource
Add hammer command to represent a new resource as a JSON file in the Git repo
- Loading branch information
Showing
7 changed files
with
86 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'hammer_cli_foregit/abstract_command' | ||
|
||
module HammerCLIForegit | ||
|
||
class Add < HammerCLIForegit::AbstractCommand | ||
|
||
option ['-r', '--resource'], 'RESOURCE', 'The Foreman resource type', | ||
:format => String | ||
option ['-f', '--file'], 'FILE', 'A JSON or YAML file to define resource attributes', | ||
:format => HammerCLI::Options::Normalizers::JSONInput.new | ||
option ['-a', '--attributes'], 'ATTRIBUTES', 'A string of resource attributes described as key=value pairs, ex: -a "name=i382,hosts=[]"', | ||
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
|
||
validate_options do | ||
option(:option_resource).required | ||
any(:option_file, :option_attributes).required | ||
end | ||
|
||
def execute | ||
super | ||
puts "Creating JSON representation of #{option_resource} resource in Git repo..." | ||
@talk.add option_resource, option_file || option_attributes | ||
@git_manager.commit("Sync #{option_resource}.") | ||
puts 'Done!' | ||
HammerCLI::EX_OK | ||
end | ||
end | ||
|
||
end | ||
|
||
HammerCLI::MainCommand.subcommand 'add', | ||
'Create a new JSON file in the Git repository for a specific resource, where its attributes are set from a file or key=value pairs', | ||
HammerCLIForegit::Add |
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