class QMK::CLI

Public Class Methods

new(args) click to toggle source
# File lib/cli.rb, line 21
def initialize(args)
  @options = parser(args)
  command, keyboard = args
  @firmware = Firmware.new(keyboard, @options[:keymap], config)

  command and self.send(parse_command(command))
end

Public Instance Methods

build() click to toggle source
# File lib/cli.rb, line 38
def build
  @firmware.make
end
clean() click to toggle source
# File lib/cli.rb, line 46
def clean
  @firmware.make 'clean'
end
flash() click to toggle source
# File lib/cli.rb, line 42
def flash
  @firmware.make @firmware.programmer
end
keyboards() click to toggle source
# File lib/cli.rb, line 50
def keyboards
  puts @firmware.keyboards
end
setup() click to toggle source
# File lib/cli.rb, line 29
def setup
  @firmware.setup
end
update() click to toggle source
# File lib/cli.rb, line 33
def update
  @firmware.update
  @firmware.update_submodules
end

Private Instance Methods

config() click to toggle source
# File lib/cli.rb, line 84
def config
  defaults = {
    standalone_keymaps: standalone_keymaps?,
    keyboards: [],
    keymaps: [],
    keymap: `whoami`.strip
  }

  if standalone_keymaps?
    c = YAML.load_file('.qmk')
            .each_with_object({}) do |(k,v), memo|
              memo[k.to_sym] = v
            end

    return defaults.merge c
  end

  return defaults
end
method_missing(*args) click to toggle source
# File lib/cli.rb, line 108
def method_missing(*args)
  puts @options[:help]
end
parse_command(cmd) click to toggle source
# File lib/cli.rb, line 80
def parse_command(cmd)
  cmd.gsub(/\-/, '_').downcase
end
parser(args) click to toggle source
# File lib/cli.rb, line 55
def parser(args)
  options = {}

  OptionParser.new do |parser|
    parser.banner = USAGE

    options[:keymap] = config[:keymap]
    parser.on("-k", "--keymap KEYMAP", "Your keymap name (default: #{options[:keymap]})") do |v|
      options[:keymap] = v
    end

    parser.on("-v", "--version", "Show qmk-cli version") do
      spec = Gem::Specification::load("qmk_cli.gemspec")
      puts spec.version
    end

    options[:help] = parser
    parser.on("-h", "--help", "Show this help message") do
      puts parser
    end
  end.parse!

  options
end
standalone_keymaps?() click to toggle source
# File lib/cli.rb, line 104
def standalone_keymaps?
  File.exists? '.qmk'
end