Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2012 07:16
Show Gist options
  • Save anonymous/1947990 to your computer and use it in GitHub Desktop.
Save anonymous/1947990 to your computer and use it in GitHub Desktop.
hammer prototype
#!/usr/bin/env ruby
# -*- encoding: UTF-8 -*-
# Derived from <http://stackoverflow.com/questions/5663519/namespacing-thor-commands-in-a-standalone-ruby-executable>
require 'rubygems'
require 'thor'
require 'thor/group'
module Hammer
class ThorSubCommandTemplate < Thor
class << self
def subcommand_setup(name, usage, desc)
namespace :"#{name}"
@subcommand_usage = usage
@subcommand_desc = desc
end
def banner(task, namespace = nil, subcommand = false)
"#{basename} #{task.formatted_usage(self, true, true)}"
end
def register_to(klass)
klass.register(self, @namespace, @subcommand_usage, @subcommand_desc)
end
end
end
class Hosts < ThorSubCommandTemplate
subcommand_setup "hosts", "hosts [TASK]", "Manage hosts"
desc "list", "list hosts"
def list
# ...
end
desc "show", "show host"
def show
# ...
end
desc "create", "create host"
def create
# ...
end
desc "delete", "delete host"
def delete
# ...
end
desc "update", "update host"
def update
# ...
end
end
class Hostgroups < ThorSubCommandTemplate
subcommand_setup "hostgroup", "hostgroup [TASK]", "Manage hostgroups"
desc "list", "list hostgroups"
def list
# ...
end
desc "show", "show hostgroup"
def show
# ...
end
desc "create", "create hostgroup"
def create
# ...
end
desc "delete", "delete hostgroup"
def delete
# ...
end
desc "update", "update hostgroup"
def update
# ...
end
end
class Domains < ThorSubCommandTemplate
subcommand_setup "domain", "domain [TASK]", "Manage domains"
desc "list", "list domains"
def list
# ...
end
desc "show", "show domain"
def show
# ...
end
desc "create", "create domain"
def create
# ...
end
desc "delete", "delete domain"
def delete
# ...
end
desc "update", "update domain"
def update
# ...
end
end
class Subnets < ThorSubCommandTemplate
subcommand_setup "subnet", "subnet [TASK]", "Manage subnets"
desc "list", "list subnets"
def list
# ...
end
desc "show", "show subnet"
def show
# ...
end
desc "create", "create subnet"
def create
# ...
end
desc "delete", "delete subnet"
def delete
# ...
end
desc "update", "update subnet"
def update
# ...
end
end
class Environments < ThorSubCommandTemplate
subcommand_setup "environment", "environment [TASK]", "Manage environments"
desc "list", "list environments"
def list
# ...
end
desc "show", "show environment"
def show
# ...
end
desc "create", "create environment"
def create
# ...
end
desc "delete", "delete environment"
def delete
# ...
end
desc "update", "update environment"
def update
# ...
end
end
class Puppetcas < ThorSubCommandTemplate
subcommand_setup "puppetca", "puppetca [TASK]", "Manage Puppet Certificate Authorities"
desc "list", "list pupetcas"
def list
# ...
end
desc "show", "show puppetca"
def show
# ...
end
desc "create", "create puppetca"
def create
# ...
end
desc "delete", "delete puppetca"
def delete
# ...
end
desc "update", "update puppetca"
def update
# ...
end
end
class CLI < Thor
Hosts.register_to(self)
Hostgroups.register_to(self)
Domains.register_to(self)
Subnets.register_to(self)
Environments.register_to(self)
Puppetcas.register_to(self)
desc "status", "Foreman server status"
def status
# ...
end
desc "dns", "Foreman server status"
def dns
# ...
end
desc "dhcp", "Foreman server status"
def dhcp
# ...
end
desc "tftp", "Foreman server status"
def tftp
# ...
end
desc "puppet", "Foreman server status"
def puppet
# ...
end
desc "server", "Perform actions on the Foreman server"
def server
# ...
end
end
end
Hammer::CLI.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment