Class: CopyWish
- Inherits:
-
Djinni::Wish
- Object
- Djinni::Wish
- CopyWish
- Defined in:
- lib/zoom/wish/copy_wish.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #description ⇒ Object
- #execute(args, djinni_env = {}) ⇒ Object
- #tab_complete(input, djinni_env = {}) ⇒ Object
- #usage ⇒ Object
Instance Method Details
#aliases ⇒ Object
4 5 6 |
# File 'lib/zoom/wish/copy_wish.rb', line 4 def aliases return ["copy", "cp"] end |
#description ⇒ Object
8 9 10 |
# File 'lib/zoom/wish/copy_wish.rb', line 8 def description return "Copy the specified profile" end |
#execute(args, djinni_env = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zoom/wish/copy_wish.rb', line 12 def execute(args, djinni_env = {}) if (args.split(" ").length != 2) usage return end config = djinni_env["config"] name, new = args.split(" ") if (!config.has_profile?(name)) puts("Profile does not exist: #{name}") elsif (config.has_profile?(new)) puts("Profile already exists: #{new}") else profiles = config.parse_profiles profiles[new] = profiles[name].clone profiles[new].name(new) config.set_profiles(profiles) end end |
#tab_complete(input, djinni_env = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zoom/wish/copy_wish.rb', line 33 def tab_complete(input, djinni_env = {}) return [{}, "", ""] if (input.include?(" ")) profiles = djinni_env["config"].parse_profiles completions = Hash.new profiles.keys.sort do |a, b| a.downcase <=> b.downcase end.each do |name| profile = profiles[name] completions[name] = profile.to_s.split("\n")[1].strip end completions.keep_if do |name, desc| name.downcase.start_with?(input.downcase) end return [completions, input, " "] end |
#usage ⇒ Object
53 54 55 56 |
# File 'lib/zoom/wish/copy_wish.rb', line 53 def usage puts("#{aliases.join(", ")} <name> <new_name>") puts(" #{description}.") end |