#!/usr/bin/env ruby $: << File.expand_path(File.dirname(__FILE__) + "/../lib") require 'rubygems' require 'commander/import' require 'bukkit.rb' program :version, Bukkit::VERSION program :description, "A Command Line Interface for CraftBukkit." command :new do |c| c.syntax = "bukkit new my-awesome-server-name [options]" c.summary = "Create a new Bukkit server." c.description = "Create a new Bukkit server with the given name." c.example "Creates a new server with the name 'my-awesome-server-name'.", "bukkit new my-awesome-server-name" c.option "--rb", "Create a new server with the recommended build." c.option "--beta", "Create a new server with the beta build." c.option "--dev", "Create a new server with the dev build." c.option "-f", "--force", "Overwrites the chosen directory if it already exists." c.action do |args, options| rb = options.rb beta = options.beta dev = options.dev force = options.force name = args.shift new_options = Hash.new # If it doesn't have a name then just stop them right there. abort "You didn't enter a server name.\nTry `bukkit new my-awesome-server-name`." if name.nil? # Add the build to the new_options hash. if rb new_options.merge!(:build => :rb) elsif beta new_options.merge!(:build => :beta) elsif dev new_options.merge!(:build => :dev) else # If the user didn't give a build option then ask for it. build = ask "Build [rb/beta/dev]: " case build when "rb", "recommended" new_options.merge!(:build => :rb) when "beta" new_options.merge!(:build => :beta) when "dev", "development" new_options.merge!(:build => :dev) else abort "Invalid build option.".red end end # Add the force option if it's needed. Adds the bool returned from 'force'. force = false if force.nil? new_options.merge!(:force => force) # Now finally send the options to the method. server = Bukkit::Server.new(name) server.create(new_options) Bukkit::Server.start end end alias_command :create, :new command :update do |c| c.syntax = "bukkit update [options]" c.summary = "Download the latest CraftBukkit version." c.description = "Download the latest CraftBukkit version from dl.bukkit.org." c.example c.summary, "bukkit update" c.option "--rb", "Update server with the recommended build." c.option "--beta", "Update server with the beta build." c.option "--dev", "Update server with the dev build." c.action do |args, options| rb = options.rb beta = options.beta dev = options.dev force = options.force update_options = Hash.new # Add the build to the new_options hash. if rb update_options.merge!(:build => :rb) elsif beta update_options.merge!(:build => :beta) elsif dev update_options.merge!(:build => :dev) else # If the user didn't give a build option then ask for it. build = ask "Build [rb/beta/dev]: ".downcase! case build when "rb", "recommended" update_options.merge!(:build => :rb) when "beta" update_options.merge!(:build => :beta) when "dev", "development" update_options.merge!(:build => :dev) else puts "Invalid build option." end end # Now finally send the options to the method. Bukkit::Server.update(update_options) end end command :start do |c| c.syntax = "bukkit start" c.summary = "Open the plugin's start in the default browser." c.description = c.summary c.option "--url", "Show just the plugin's URL." c.option "-r", "--ram MEMORY", Integer, "Specify the amount of RAM." c.example "Start a bukkit server.", "bukkit start" c.example "Start a bukkit server with a specified amount of RAM (in megabytes.", "bukkit start --ram 1000" c.action do |args, options| @ram = options.default[:ram] start_options = { :ram => @ram.to_i } Bukkit::Server.start(start_options) end end command :website do |c| c.syntax = "bukkit website [options]" c.summary = "Open the plugin's website in the default browser." c.description = c.summary c.example c.summary, "bukkit website plugin-name" c.example "Show just the plugin's URL.", "bukkit website plugin-name --url" c.option "--url", "Show just the plugin's URL." c.action do |args, options| plugin_name = args.shift abort "You didn't enter a plugin name." if plugin_name.empty? plugin = Bukkit::Plugin.new(plugin_name) if options.url puts " Website: ".yellow + plugin.website else plugin.view_website end end end command :install do |c| c.syntax = "bukkit install my-favorite-plugin" c.summary = "Install a plugin to your server." c.description = c.summary c.example c.summary, "bukkit install my-favorite-plugin" c.action do |args, options| name = args.shift if name.empty? abort "You didn't enter a plugin name." else plugin = Bukkit::Plugin.new(name) plugin.install end end end