module CodeSnippet::CLI::Commands
CLI
Actions
Public Class Methods
list( lang, _copy, _args = [] )
click to toggle source
List lists snippets
# 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 = [] )
click to toggle source
Show snippet directory path
# 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 = [] )
click to toggle source
Show displays a snippet
# 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 = [] )
click to toggle source
Show snippet gem version
# File lib/code_snippet/cli/commands.rb, line 73 def self.version( _lang, _copy, _args = [] ) CLI.print_message(CodeSnippet::VERSION) end