Class: DeleteWish

Inherits:
Djinni::Wish
  • Object
show all
Defined in:
lib/zoom/wish/delete_wish.rb

Instance Method Summary collapse

Instance Method Details

#aliasesObject



4
5
6
# File 'lib/zoom/wish/delete_wish.rb', line 4

def aliases
    return ["delete", "rm"]
end

#descriptionObject



8
9
10
# File 'lib/zoom/wish/delete_wish.rb', line 8

def description
    return "Delete the specifed profile"
end

#execute(args, djinni_env = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zoom/wish/delete_wish.rb', line 12

def execute(args, djinni_env = {})
    config = djinni_env["config"]
    profiles = config.parse_profiles
    args.split(" ").each do |arg|
        if (!config.has_profile?(arg))
            puts("Profile does not exist: #{arg}")
        elsif (config.get_current_profile_name == arg)
            puts("Can't delete current profile: #{arg}")
        else
            profiles.delete(arg)
        end
    end
    config.set_profiles(profiles)
end

#tab_complete(input, djinni_env = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zoom/wish/delete_wish.rb', line 27

def tab_complete(input, djinni_env = {})
    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

    last = input.rpartition(" ")[-1]

    completions.keep_if do |name, desc|
        name.downcase.start_with?(last.downcase)
    end

    return [completions, last, " "]
end

#usageObject



47
48
49
50
# File 'lib/zoom/wish/delete_wish.rb', line 47

def usage
    puts("#{aliases.join(", ")} <name>...[name]")
    puts("    #{description}.")
end