Class: ShowWish

Inherits:
Djinni::Wish
  • Object
show all
Defined in:
lib/rubeepass/wish/show_wish.rb

Instance Method Summary collapse

Instance Method Details

#aliasesObject



4
5
6
# File 'lib/rubeepass/wish/show_wish.rb', line 4

def aliases
    return ["cat", "show", "showall"]
end

#descriptionObject



8
9
10
# File 'lib/rubeepass/wish/show_wish.rb', line 8

def description
    "Show group/entry contents (showall includes passwords)"
end

#execute(args, djinni_env = Hash.new) ⇒ 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
# File 'lib/rubeepass/wish/show_wish.rb', line 12

def execute(args, djinni_env = Hash.new)
    keepass = djinni_env["keepass"]
    cwd = djinni_env["cwd"]

    args = cwd.path if (args.empty?)
    path = keepass.absolute_path(args, cwd.path)
    path, found, target = path.rpartition("/")
    new_cwd = keepass.find_group(path)

    if (new_cwd.nil?)
        puts "Group not found"
        return
    end

    if (target.empty?)
        case djinni_env["djinni_input"]
        when "showall"
            puts new_cwd.details(0, true)
        else
            puts new_cwd
        end
    elsif (new_cwd.has_group?(target))
        case djinni_env["djinni_input"]
        when "showall"
            puts new_cwd.groups[target].details(0, true)
        else
            puts new_cwd.groups[target]
        end
    elsif (new_cwd.has_entry?(target))
        new_cwd.entry_titles.select do |entry|
            target.downcase == entry.downcase
        end.each do |entry|
            case djinni_env["djinni_input"]
            when "showall"
                puts new_cwd.entries[entry].details(0, true)
            else
                puts new_cwd.entries[entry]
            end
        end
    else
        puts "Group/Entry not found"
    end
end

#tab_complete(input, djinni_env = Hash.new) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rubeepass/wish/show_wish.rb', line 56

def tab_complete(input, djinni_env = Hash.new)
    cwd = djinni_env["cwd"]
    groups, entries = cwd.fuzzy_find(input)

    completions = Hash.new
    groups.each do |group|
        completions[group] = "Group"
    end
    entries.each do |entry|
        completions[entry] = "Entry"
    end

    append = "/"
    append = "" if (groups.empty?)

    return [completions, input.rpartition("/")[-1], append]
end

#usageObject



74
75
76
77
# File 'lib/rubeepass/wish/show_wish.rb', line 74

def usage
    puts "#{aliases.join(", ")} [group|entry]"
    puts "    #{description}."
end