mirror of
https://github.com/tmuxinator/tmuxinator.git
synced 2026-03-11 18:24:23 -05:00
Reduce duplication in CLI descriptions.
This commit is contained in:
@@ -7,7 +7,7 @@ require "tmuxinator"
|
||||
if ARGV.length == 1
|
||||
name = ARGV[0]
|
||||
|
||||
if Tmuxinator::Cli.new.command_hash.keys.include?(name.to_sym)
|
||||
if Tmuxinator::Cli::COMMANDS.keys.include?(name.to_sym)
|
||||
Tmuxinator::Cli.start
|
||||
elsif Tmuxinator::Config.exists?(name)
|
||||
Tmuxinator::Cli.new.start(name)
|
||||
|
||||
@@ -2,44 +2,38 @@ module Tmuxinator
|
||||
class Cli < Thor
|
||||
include Tmuxinator::Util
|
||||
|
||||
attr_reader :command_hash
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
|
||||
@command_hash = {
|
||||
commands: "Lists commands available in tmuxinator",
|
||||
completions: "Used for shell completion",
|
||||
new: "Create a new project file and open it in your editor",
|
||||
open: "Alias of new",
|
||||
start: "Start a tmux session using a project's tmuxinator config",
|
||||
debug: "Output the shell commands that are generated by tmuxinator",
|
||||
copy: "Copy an existing project to a new project and open it in your editor",
|
||||
delete: "Deletes given project",
|
||||
implode: "Deletes all tmuxinator projects",
|
||||
version: "Display installed tmuxinator version",
|
||||
doctor: "Look for problems in your configuration"
|
||||
}
|
||||
|
||||
end
|
||||
COMMANDS = {
|
||||
commands: "Lists commands available in tmuxinator",
|
||||
completions: "Used for shell completion",
|
||||
new: "Create a new project file and open it in your editor",
|
||||
open: "Alias of new",
|
||||
start: "Start a tmux session using a project's tmuxinator config",
|
||||
debug: "Output the shell commands that are generated by tmuxinator",
|
||||
copy: "Copy an existing project to a new project and open it in your editor",
|
||||
delete: "Deletes given project",
|
||||
implode: "Deletes all tmuxinator projects",
|
||||
version: "Display installed tmuxinator version",
|
||||
doctor: "Look for problems in your configuration",
|
||||
list: "Lists all tmuxinator projects"
|
||||
}
|
||||
|
||||
package_name "tmuxinator" unless Gem::Version.create(Thor::VERSION) < Gem::Version.create("0.18")
|
||||
|
||||
desc "commands", "Lists commands available in tmuxinator"
|
||||
desc "commands", COMMANDS[:commands]
|
||||
|
||||
def commands(shell = nil)
|
||||
out = if shell == "zsh"
|
||||
command_hash.map do |command, desc|
|
||||
COMMANDS.map do |command, desc|
|
||||
"#{command}:#{desc}"
|
||||
end.join("\n")
|
||||
else
|
||||
command_hash.keys.join("\n")
|
||||
COMMANDS.keys.join("\n")
|
||||
end
|
||||
|
||||
puts out
|
||||
end
|
||||
|
||||
desc "completions [arg1 arg2]", "Used for shell completion"
|
||||
desc "completions [arg1 arg2]", COMMANDS[:completions]
|
||||
|
||||
def completions(arg)
|
||||
if %w(start open copy delete).include?(arg)
|
||||
@@ -48,7 +42,7 @@ module Tmuxinator
|
||||
end
|
||||
end
|
||||
|
||||
desc "new [PROJECT]", "Create a new project file and open it in your editor"
|
||||
desc "new [PROJECT]", COMMANDS[:new]
|
||||
map "open" => :new
|
||||
map "o" => :new
|
||||
map "n" => :new
|
||||
@@ -65,7 +59,7 @@ module Tmuxinator
|
||||
Kernel.system("$EDITOR #{config}") || doctor
|
||||
end
|
||||
|
||||
desc "start [PROJECT]", "Start a tmux session using a project's tmuxinator config"
|
||||
desc "start [PROJECT]", COMMANDS[:start]
|
||||
map "s" => :start
|
||||
|
||||
def start(name)
|
||||
@@ -81,14 +75,14 @@ module Tmuxinator
|
||||
Kernel.exec(project.render)
|
||||
end
|
||||
|
||||
desc "debug [PROJECT]", "Output the shell commands that are generated by tmuxinator"
|
||||
desc "debug [PROJECT]", COMMANDS[:debug]
|
||||
|
||||
def debug(name)
|
||||
project = Tmuxinator::Config.validate(name)
|
||||
puts project.render
|
||||
end
|
||||
|
||||
desc "copy [EXISTING] [NEW]", "Copy an existing project to a new project and open it in your editor"
|
||||
desc "copy [EXISTING] [NEW]", COMMANDS[:copy]
|
||||
map "c" => :copy
|
||||
map "cp" => :copy
|
||||
|
||||
@@ -106,7 +100,7 @@ module Tmuxinator
|
||||
Kernel.system("$EDITOR #{new_config_path}")
|
||||
end
|
||||
|
||||
desc "delete [PROJECT]", "Deletes given project"
|
||||
desc "delete [PROJECT]", COMMANDS[:delete]
|
||||
map "d" => :delete
|
||||
map "rm" => :delete
|
||||
|
||||
@@ -123,7 +117,7 @@ module Tmuxinator
|
||||
end
|
||||
end
|
||||
|
||||
desc "implode", "Deletes all tmuxinator projects"
|
||||
desc "implode", COMMANDS[:implode]
|
||||
map "i" => :implode
|
||||
|
||||
def implode
|
||||
@@ -133,7 +127,7 @@ module Tmuxinator
|
||||
end
|
||||
end
|
||||
|
||||
desc "list", "Lists all tmuxinator projects"
|
||||
desc "list", COMMANDS[:list]
|
||||
map "l" => :list
|
||||
map "ls" => :list
|
||||
|
||||
@@ -143,14 +137,14 @@ module Tmuxinator
|
||||
print_in_columns Tmuxinator::Config.configs
|
||||
end
|
||||
|
||||
desc "version", "Display installed tmuxinator version"
|
||||
desc "version", COMMANDS[:version]
|
||||
map "-v" => :version
|
||||
|
||||
def version
|
||||
say "tmuxinator #{Tmuxinator::VERSION}"
|
||||
end
|
||||
|
||||
desc "doctor", "Look for problems in your configuration"
|
||||
desc "doctor", COMMANDS[:doctor]
|
||||
|
||||
def doctor
|
||||
say "Checking if tmux is installed ==> "
|
||||
|
||||
@@ -36,7 +36,7 @@ describe Tmuxinator::Cli do
|
||||
|
||||
it "lists the commands" do
|
||||
out, _ = capture_io { cli.start }
|
||||
expect(out).to eq "#{%w(commands completions new open start debug copy delete implode version doctor).join("\n")}\n"
|
||||
expect(out).to eq "#{%w(commands completions new open start debug copy delete implode version doctor list).join("\n")}\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user