Skip to content

Commit

Permalink
Add --list-yaml option.
Browse files Browse the repository at this point in the history
  • Loading branch information
clonezone committed Apr 23, 2015
1 parent c073d17 commit 83539c0
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 15 deletions.
6 changes: 5 additions & 1 deletion Changes
Expand Up @@ -12,11 +12,15 @@ v1.xx.xx - 2015/xx/xx

New features:

- New --list-yaml option to get --list-dependencies and --list-variables to
emit their data as YAML (http://yaml.org).

- New --list-json option to get --list-dependencies and --list-variables to
emit their data as JSON (http://json.org). Note that JSON isn't exactly
ideal for representing the directed acyclic graph that even a mildly
complicated set of dependencies can result in and you can end up with large
amounts of duplicate data in the output.
amounts of duplicate data in the output. If you can handle parsing YAML,
you are probably better off with that.

Miscellaneous:

Expand Down
46 changes: 46 additions & 0 deletions lib/fig/command/action/list_dependencies/yaml.rb
@@ -0,0 +1,46 @@
# coding: utf-8

require 'fig/command/action'
require 'fig/command/action/role/list_as_yaml'
require 'fig/command/action/role/list_base_config'
require 'fig/command/action/role/list_dependencies_from_data_structure'
require 'fig/command/action/role/list_from_data_structure'
require 'fig/command/action/role/list_walking_dependency_tree'

module Fig; end
class Fig::Command; end
module Fig::Command::Action; end
class Fig::Command::Action::ListDependencies; end

class Fig::Command::Action::ListDependencies::YAML
include Fig::Command::Action
include Fig::Command::Action::Role::ListAsYAML
include Fig::Command::Action::Role::ListBaseConfig
include Fig::Command::Action::Role::ListDependenciesFromDataStructure
include Fig::Command::Action::Role::ListFromDataStructure
include Fig::Command::Action::Role::ListWalkingDependencyTree

def options()
return %w<--list-dependencies --list-yaml>
end

def descriptor_requirement()
return nil
end

def load_base_package?()
return true
end

def register_base_package?()
return nil # don't care
end

def apply_config?()
return nil # don't care
end

def apply_base_config?()
return nil # don't care
end
end
46 changes: 46 additions & 0 deletions lib/fig/command/action/list_dependencies/yaml_all_configs.rb
@@ -0,0 +1,46 @@
# coding: utf-8

require 'fig/command/action'
require 'fig/command/action/role/list_all_configs'
require 'fig/command/action/role/list_as_yaml'
require 'fig/command/action/role/list_dependencies_from_data_structure'
require 'fig/command/action/role/list_from_data_structure'
require 'fig/command/action/role/list_walking_dependency_tree'

module Fig; end
class Fig::Command; end
module Fig::Command::Action; end
class Fig::Command::Action::ListDependencies; end

class Fig::Command::Action::ListDependencies::YAMLAllConfigs
include Fig::Command::Action
include Fig::Command::Action::Role::ListAllConfigs
include Fig::Command::Action::Role::ListAsYAML
include Fig::Command::Action::Role::ListDependenciesFromDataStructure
include Fig::Command::Action::Role::ListFromDataStructure
include Fig::Command::Action::Role::ListWalkingDependencyTree

def options()
return %w<--list-dependencies --list-yaml --list-all-configs>
end

def descriptor_requirement()
return nil
end

def load_base_package?()
return true
end

def register_base_package?()
return nil # don't care
end

def apply_config?()
return nil # don't care
end

def apply_base_config?()
return nil # don't care
end
end
26 changes: 26 additions & 0 deletions lib/fig/command/action/list_variables/yaml.rb
@@ -0,0 +1,26 @@
# coding: utf-8

require 'fig/command/action'
require 'fig/command/action/role/list_as_yaml'
require 'fig/command/action/role/list_base_config'
require 'fig/command/action/role/list_from_data_structure'
require 'fig/command/action/role/list_variables_from_data_structure'
require 'fig/command/action/role/list_walking_dependency_tree'

module Fig; end
class Fig::Command; end
module Fig::Command::Action; end
class Fig::Command::Action::ListVariables; end

class Fig::Command::Action::ListVariables::YAML
include Fig::Command::Action
include Fig::Command::Action::Role::ListAsYAML
include Fig::Command::Action::Role::ListBaseConfig
include Fig::Command::Action::Role::ListFromDataStructure
include Fig::Command::Action::Role::ListVariablesFromDataStructure
include Fig::Command::Action::Role::ListWalkingDependencyTree

def options()
return %w<--list-variables --list-yaml>
end
end
26 changes: 26 additions & 0 deletions lib/fig/command/action/list_variables/yaml_all_configs.rb
@@ -0,0 +1,26 @@
# coding: utf-8

require 'fig/command/action'
require 'fig/command/action/role/list_all_configs'
require 'fig/command/action/role/list_as_yaml'
require 'fig/command/action/role/list_from_data_structure'
require 'fig/command/action/role/list_variables_from_data_structure'
require 'fig/command/action/role/list_walking_dependency_tree'

module Fig; end
class Fig::Command; end
module Fig::Command::Action; end
class Fig::Command::Action::ListVariables; end

class Fig::Command::Action::ListVariables::YAMLAllConfigs
include Fig::Command::Action
include Fig::Command::Action::Role::ListAllConfigs
include Fig::Command::Action::Role::ListAsYAML
include Fig::Command::Action::Role::ListFromDataStructure
include Fig::Command::Action::Role::ListVariablesFromDataStructure
include Fig::Command::Action::Role::ListWalkingDependencyTree

def options()
return %w<--list-variables --list-yaml --list-all-configs>
end
end
19 changes: 19 additions & 0 deletions lib/fig/command/action/role/list_as_yaml.rb
@@ -0,0 +1,19 @@
# coding: utf-8

require 'yaml'

module Fig; end
class Fig::Command; end
module Fig::Command::Action; end
module Fig::Command::Action::Role; end

# Requires a #set_up_object_to_be_serialized method.
module Fig::Command::Action::Role::ListAsYAML
def execute()
set_up_object_to_be_serialized

YAML.dump @object_to_be_serialized, $stdout

return Fig::Command::Action::EXIT_SUCCESS
end
end
12 changes: 6 additions & 6 deletions lib/fig/command/action/role/list_from_data_structure.rb
Expand Up @@ -46,8 +46,8 @@ def include_gather
visited << edge

including_hash = @package_configs[including_package][including_config]
including_hash[:dependencies] ||= []
including_hash[:dependencies] <<
including_hash['dependencies'] ||= []
including_hash['dependencies'] <<
@package_configs[included_package][included_config]
end
end
Expand Down Expand Up @@ -75,15 +75,15 @@ def new_package_config_hash(package, config_name)
hash = {}

if package.name
hash[:name] = package.name
hash['name'] = package.name
end
if package.version
hash[:version] = package.version
hash['version'] = package.version
end
if package.description
hash[:description] = package.description
hash['description'] = package.description
end
hash[:config] = config_name
hash['config'] = config_name

return hash
end
Expand Down
Expand Up @@ -30,7 +30,7 @@ def node_content(package, config_name)
hash = new_package_config_hash package, config_name
statements = variable_statements package, config_name
if not statements.empty?
hash[:variables] = statements
hash['variables'] = statements
end

return hash
Expand All @@ -52,9 +52,9 @@ def variable_statements(package, config_name)

def hash_for_variable_statement(statement)
return {
:type => statement.statement_type,
:name => statement.name,
:value => statement.tokenized_value.to_escaped_string,
'type' => statement.statement_type,
'name' => statement.name,
'value' => statement.tokenized_value.to_escaped_string,
}
end
end
44 changes: 40 additions & 4 deletions lib/fig/command/options.rb
Expand Up @@ -17,6 +17,8 @@
require 'fig/command/action/list_dependencies/json_all_configs'
require 'fig/command/action/list_dependencies/tree'
require 'fig/command/action/list_dependencies/tree_all_configs'
require 'fig/command/action/list_dependencies/yaml'
require 'fig/command/action/list_dependencies/yaml_all_configs'
require 'fig/command/action/list_local'
require 'fig/command/action/list_remote'
require 'fig/command/action/list_variables'
Expand All @@ -28,6 +30,8 @@
require 'fig/command/action/list_variables/json_all_configs'
require 'fig/command/action/list_variables/tree'
require 'fig/command/action/list_variables/tree_all_configs'
require 'fig/command/action/list_variables/yaml'
require 'fig/command/action/list_variables/yaml_all_configs'
require 'fig/command/action/options'
require 'fig/command/action/publish'
require 'fig/command/action/publish_local'
Expand Down Expand Up @@ -197,6 +201,10 @@ def list_json?()
return @list_json
end

def list_yaml?()
return @list_yaml
end

def graphviz?()
return @graphviz
end
Expand Down Expand Up @@ -642,11 +650,17 @@ def set_up_listings()
end

@parser.on(
'--list-json', 'for listings, output JSON instead of a list'
'--list-json', 'for listings, output JSON (http://json.org)'
) do
@list_json = true
end

@parser.on(
'--list-yaml', 'for listings, output YAML (http://yaml.org)'
) do
@list_yaml = true
end

@parser.on(
'--graphviz',
'for listings, output DOT (http://graphviz.org/content/dot-language)'
Expand Down Expand Up @@ -864,6 +878,10 @@ def validate()
raise Fig::Command::OptionError.new(
'Cannot use --suppress-all-includes/--suppress-cross-package-includes with --list-json.'
)
elsif list_yaml?
raise Fig::Command::OptionError.new(
'Cannot use --suppress-all-includes/--suppress-cross-package-includes with --list-yaml.'
)
elsif graphviz?
raise Fig::Command::OptionError.new(
'Cannot use --suppress-all-includes/--suppress-cross-package-includes with --graphviz.'
Expand All @@ -889,6 +907,8 @@ def validate()
validate_list_option '--list-tree'
elsif list_json?
validate_list_option '--list-json'
elsif list_yaml?
validate_list_option '--list-yaml'
elsif graphviz?
validate_list_option '--graphviz'
elsif list_all_configs?
Expand All @@ -900,16 +920,30 @@ def validate()
raise Fig::Command::OptionError.new(
'Cannot use --list-tree and --graphviz at the same time.'
)
elsif list_json?
raise Fig::Command::OptionError.new(
'Cannot use --list-tree and --list-json at the same time.'
)
elsif list_yaml?
raise Fig::Command::OptionError.new(
'Cannot use --list-tree and --list-json at the same time.'
)
end
end
if graphviz?
if list_json?
raise Fig::Command::OptionError.new(
'Cannot use --list-tree and --list-json at the same time.'
'Cannot use --graphviz and --list-json at the same time.'
)
elsif list_yaml?
raise Fig::Command::OptionError.new(
'Cannot use --graphviz and --list-yaml at the same time.'
)
end
end
if graphviz? and list_json?
if list_json? and list_yaml?
raise Fig::Command::OptionError.new(
'Cannot use --graphviz and --list-json at the same time.'
'Cannot use --list-json and --list-yaml at the same time.'
)
end

Expand Down Expand Up @@ -957,6 +991,8 @@ def set_up_sub_actions()
sub_action_name = list_all_configs? ? :TreeAllConfigs : :Tree
elsif list_json?
sub_action_name = list_all_configs? ? :JSONAllConfigs : :JSON
elsif list_yaml?
sub_action_name = list_all_configs? ? :YAMLAllConfigs : :YAML
elsif graphviz?
sub_action_name = list_all_configs? ? :GraphvizAllConfigs : :Graphviz
elsif list_all_configs?
Expand Down

0 comments on commit 83539c0

Please sign in to comment.