Created
December 1, 2017 15:17
-
-
Save juliojgarciaperez/fc872ff8c8b87f9d838fbd2a73d8964a to your computer and use it in GitHub Desktop.
Shuttle to bash alias
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
require 'json' | |
if ARGV.length != 1 | |
puts 'usage: ruby shuttle_alias.rb path_to_shuttle_config.json' | |
exit | |
end | |
config = JSON.parse File.read(ARGV[0]) | |
puts '# Alias from Shuttle' | |
def perform(node, path = []) | |
if node.is_a?(Hash) | |
if node['name'] | |
path << node['name'] | |
alias_name = path.map(&:downcase).join('_') | |
puts "alias ssh_#{alias_name}='#{node['cmd']}'" | |
else | |
node.each do |key, value| | |
perform(value, path.dup + [key]) | |
end | |
end | |
else | |
node.each do |value| | |
perform(value, path.dup) | |
end | |
end | |
end | |
perform config['hosts'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment