Class: HeroShell::HerokuCommandsCache

Inherits:
Object
  • Object
show all
Defined in:
lib/heroshell/heroku_command_cache.rb

Constant Summary collapse

@@TOPICS_FILE =
"#{ENV['HOME']}/.heroku-commands.list"

Class Method Summary collapse

Class Method Details

.get_commands(forceSync) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/heroshell/heroku_command_cache.rb', line 29

def self.get_commands(forceSync)
    def self.read_topics_file()
        IO.read(@@TOPICS_FILE).split("\n")
    end

    if !File.exist? @@TOPICS_FILE || forceSync
        puts "No commands file found, or sync forced - syncing..."
        sync()
        puts "Syncing done."
        read_topics_file()
    else
        read_topics_file()
    end
end

.read_help_topicsObject



5
6
7
8
9
10
# File 'lib/heroshell/heroku_command_cache.rb', line 5

def self.read_help_topics()
    lines = `heroku help`.split("\n").drop(4)
    lines
    .select { |l| l[1] != ' ' }
    .collect { |l| l.strip().split(' ')[0] }
end

.read_topic(topic) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/heroshell/heroku_command_cache.rb', line 12

def self.read_topic(topic) 
    lines = `heroku help #{topic}`.split("\n")
    lines
    .drop_while { |line| !line.start_with? " -a, --app" }
    .drop_while { |line| !line.start_with? "heroku #{topic} commands" }
    .drop(1)
    .select { |l| l[1] != ' ' }
    .collect { |l| l.strip().split(' ')[0] }
end

.read_topics_fileObject



30
31
32
# File 'lib/heroshell/heroku_command_cache.rb', line 30

def self.read_topics_file()
    IO.read(@@TOPICS_FILE).split("\n")
end

.syncObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/heroshell/heroku_command_cache.rb', line 4

def self.sync()
    def self.read_help_topics()
        lines = `heroku help`.split("\n").drop(4)
        lines
        .select { |l| l[1] != ' ' }
        .collect { |l| l.strip().split(' ')[0] }
    end

    def self.read_topic(topic) 
        lines = `heroku help #{topic}`.split("\n")
        lines
        .drop_while { |line| !line.start_with? " -a, --app" }
        .drop_while { |line| !line.start_with? "heroku #{topic} commands" }
        .drop(1)
        .select { |l| l[1] != ' ' }
        .collect { |l| l.strip().split(' ')[0] }
    end

    File.open(@@TOPICS_FILE, "w+") { |f| 
        f.write(read_help_topics()
                .flat_map{ |t| read_topic(t) }
                .join("\n"))
    }
end