class SublimeTextKit::CLI

The Command Line Interface (CLI) for the gem.

Attributes

ascii_doc_printer[R]
markdown_printer[R]

Public Class Methods

configuration() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 14
def self.configuration
  Runcom::Config.new "#{Identity::NAME}/configuration.yml"
end
new(args = [], options = {}) click to toggle source

Initialize.

Calls superclass method
# File lib/sublime_text_kit/cli.rb, line 19
def initialize args = [], options = {}, config = {}
  super args, options, config
  @markdown_printer = Snippets::Printers::Markdown.new
  @ascii_doc_printer = Snippets::Printers::ASCIIDoc.new
end

Public Instance Methods

config() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 98
def config
  path = self.class.configuration.current

  if options.edit? then `#{ENV["EDITOR"]} #{path}`
  elsif options.info?
    path ? say(path) : say("Configuration doesn't exist.")
  else help :config
  end
end
help(task = nil) click to toggle source
Calls superclass method
# File lib/sublime_text_kit/cli.rb, line 116
def help task = nil
  say and super
end
metadata() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 74
def metadata
  say

  if options.create? then create_metadata
  elsif options.destroy? then destroy_metadata
  elsif options.rebuild? then rebuild_metadata
  else help "--metadata"
  end

  say
end
session() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 40
def session
  say
  options.rebuild? ? rebuild_session : help("--session")
  say
end
snippets() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 58
def snippets
  say

  if options.ascii_doc? then ascii_doc_printer.call
  elsif options.markdown? then markdown_printer.call
  else help "--snippets"
  end

  say
end
update() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 27
def update
  create_metadata
  say
  rebuild_session
end
version() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 110
def version
  say Identity::VERSION_LABEL
end

Private Instance Methods

create_metadata() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 132
def create_metadata
  say_status :info, "Creating metadata...", :green
  say_status :info, "Metadata Path: #{metadata_dir}", :green
  project_roots.each do |project_root|
    say_status :info, "Processing project root: #{File.expand_path project_root}...", :green
    Metadata::Project.create project_root, metadata_dir
    Metadata::Workspace.create project_root, metadata_dir
  end
  say_status :info, "Metadata created.", :green
end
destroy_metadata() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 143
def destroy_metadata
  if yes? "Delete metadata in #{metadata_dir}?"
    say_status :info, "Deleting metadata...", :green
    Metadata::Project.delete metadata_dir
    Metadata::Workspace.delete metadata_dir
    say_status :info, "Metadata deleted.", :green
  else
    say_status :info, "Metadata deletion aborted.", :green
  end
end
metadata_dir() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 128
def metadata_dir
  @metadata_dir ||= File.expand_path self.class.configuration.to_h.fetch(:metadata_dir)
end
project_roots() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 124
def project_roots
  @project_roots ||= self.class.configuration.to_h.fetch :project_roots, []
end
rebuild_metadata() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 154
def rebuild_metadata
  if yes? "Rebuild metadata in #{metadata_dir}?"
    say_status :info, "Deleting metadata...", :green
    Metadata::Project.delete metadata_dir
    Metadata::Workspace.delete metadata_dir

    say_status :info, "Creating metadata...", :green
    project_roots.each do |project_root|
      say_status :info, "Processing project root: #{File.expand_path project_root}...", :green
      Metadata::Project.create project_root, metadata_dir
      Metadata::Workspace.create project_root, metadata_dir
    end

    say_status :info, "Metadata rebuilt.", :green
  else
    say_status :info, "Metadata rebuild aborted.", :green
  end
end
rebuild_session() click to toggle source
# File lib/sublime_text_kit/cli.rb, line 173
def rebuild_session
  say_status :info, "Rebuilding session metadata...", :green
  say_status :info, "Metadata (project/workspace) Path: #{metadata_dir}", :green
  say_status :info, "Session Path: #{Session.session_path}", :green
  session = Session.new metadata_dir
  session.rebuild_recent_workspaces
  say_status :info, "Session metadata rebuilt.", :green
end