class HeroShell::HerokuCommandsCache

Public Class Methods

get_commands(forceSync) click to toggle source
# 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_topics() click to toggle source
# 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) click to toggle source
# 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_file() click to toggle source
# File lib/heroshell/heroku_command_cache.rb, line 30
def self.read_topics_file()
    IO.read(@@TOPICS_FILE).split("\n")
end
sync() click to toggle source
# 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