Module: CodeSnippet::CLI::Commands

Defined in:
lib/code_snippet/cli/commands.rb

Overview

CLI Actions

Class Method Summary collapse

Class Method Details

.list(lang, _copy, _args = []) ⇒ Object

List lists snippets



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/code_snippet/cli/commands.rb', line 44

def self.list(
  lang,
  _copy,
  _args = []
)
  snippet_dir = CodeSnippet::CLI.snip_dir

  manager = CodeSnippet::Manager.new(snippet_dir)
  manager.load_snippets

  snippets = lang ? manager.filter_by_extension(lang) : manager.snippets

  CLI::Presenters.list_snippets(snippets)
end

.path(_lang, _copy, _args = []) ⇒ Object

Show snippet directory path



62
63
64
65
66
67
68
# File 'lib/code_snippet/cli/commands.rb', line 62

def self.path(
  _lang,
  _copy,
  _args = []
)
  CLI.print_message(CLI.snip_dir)
end

.show(lang, copy, args = []) ⇒ Object

Show displays a snippet



11
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
# File 'lib/code_snippet/cli/commands.rb', line 11

def self.show(
  lang,
  copy,
  args = []
)
  name = args.first
  snippet_dir = CodeSnippet::CLI.snip_dir

  manager = CodeSnippet::Manager.new(snippet_dir)
  manager.load_snippets

  snips = manager.find(name, lang)
  raise "unable to find #{name}" if snips.empty?

  snip = snips.first
  if snips.length > 1
    snip = CLI::Presenters.pick_from(
      'Multiple snippets found, which one would you like to view?',
      snips
    )
  end

  if copy
    Clipboard.copy(snip.content)
    CLI.print_message("COPIED: #{snip.path}")
  end

  CLI::Presenters.show(snip)
end

.version(_lang, _copy, _args = []) ⇒ Object

Show snippet gem version



73
74
75
76
77
78
79
# File 'lib/code_snippet/cli/commands.rb', line 73

def self.version(
  _lang,
  _copy,
  _args = []
)
  CLI.print_message(CodeSnippet::VERSION)
end