Class: EditWish

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

Instance Method Summary collapse

Constructor Details

#initializeEditWish

Returns a new instance of EditWish.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/zoom/wish/edit_wish.rb', line 64

def initialize
    @classes = Hash.new
    [Zoom::Profile].concat(Zoom::Profile.subclasses).each do |c|
        @classes[c.to_s] = c.new(c.to_s).to_s.split("\n")[1].strip
    end
    @fields = {
        "after" => "Append any follow up commands",
        "before" => "Prepend any ENV vars",
        "class" => "Modify the class",
        "flags" => "Specify any additional flags",
        "tool" => "Specify an alternative tool"
    }
end

Instance Method Details

#aliasesObject



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

def aliases
    return ["config", "edit", "set"]
end

#descriptionObject



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

def description
    return "Configure 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zoom/wish/edit_wish.rb', line 12

def execute(args, djinni_env = {})
    n, args = args.split(" ", 2)

    if (args.nil?)
        usage
        return
    end

    config = djinni_env["config"]
    if (!config.has_profile?(n))
        puts("Profile does not exist: #{n}")
        return
    end

    f, found, v = args.partition(" ")

    case f
    when "class", "tool"
        if (found.empty?)
            usage
            return
        end
    end

    profiles = config.parse_profiles
    profile = profiles[n]

    case f
    when "after"
        profile.after(v)
    when "before"
        profile.before(v)
    when "class"
        if (!@classes.has_key?(v))
            puts("Class does not exist: #{v}")
            return
        end

        profile = Zoom::Profile.profile_by_name(v).new(n)
        profiles[n] = profile
    when "flags"
        profile.flags(v)
    when "tool"
        profile.tool(v)
    else
        usage
        return
    end

    config.set_profiles(profiles)
end

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



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/zoom/wish/edit_wish.rb', line 78

def tab_complete(input, djinni_env = {})
    n, input = input.split(" ", 2)
    n ||= ""

    if (input.nil?)
        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?(n.downcase)
        end

        return [completions, n, " "]
    end

    f, found, v = input.rpartition(" ")

    if (found.empty?)
        f = v
        completions = @fields.select do |field, desc|
            field.downcase.start_with?(f.downcase)
        end
        return [completions, f, " "]
    end

    case f
    when "class"
        completions = @classes.select do |clas, desc|
            clas.downcase.start_with?(v.downcase)
        end
        return [completions, v, ""]
    else
        return [{}, "", ""]
    end
end

#usageObject



121
122
123
124
125
126
127
128
129
# File 'lib/zoom/wish/edit_wish.rb', line 121

def usage
    puts("#{aliases.join(", ")} <name> <field> <value>")
    puts("    #{description}.")
    puts
    puts("FIELDS")
    @fields.each do |field, desc|
        puts("    #{field}")
    end
end