code_snippet 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b3be1025b2ca9038e8efa67c202272d75d9106847af59912d94402f4fdefb02a
4
+ data.tar.gz: f74a1eeb89ef415b879029e093dbcb50dec4263d86200185dcb5f2a5de23eca6
5
+ SHA512:
6
+ metadata.gz: a02f2a04c6a5e97f75c3de4a2c1c0aeb6a0477a7ef6fd4089e88962bfe538dafd77d9ff12c09c9ec90d28f1cf932a2515d9f11666c0ecbc278be209f7fc74843
7
+ data.tar.gz: d4ad4736c97d2be4fe77dfea10e2c3ad01da85b46dbf03634b7c3a590570b367860ce16ab5bb86948fd93d1e9ce88cc8f21df6205ae370a22e8efb1899d91681
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.6', '2.7']
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
19
+ with:
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ bundler-cache: true
22
+ - name: Run tests
23
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /pkg/
6
+ /spec/reports/
7
+ /tmp/
8
+
9
+ # rspec failure tracking
10
+ .rspec_status
11
+
12
+ # byebug history
13
+ .byebug_history
14
+
15
+ *.gem
16
+ target/reports
17
+
18
+ .DS_Store
19
+
20
+ /doc/
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: 2.4
4
+
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ Max: 20
10
+
11
+ Metrics/AbcSize:
12
+ Max: 20
13
+
14
+ Lint/AssignmentInCondition:
15
+ Enabled: false
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - 'code_snippet.gemspec'
20
+ - 'spec/**/*'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.6
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,51 @@
1
+ # Contributing
2
+
3
+ When contributing to CodeSnippet, please take note of the following requests.
4
+
5
+ ## Pull Request Process
6
+
7
+ 1. Before raising a pull request, please first discuss the change by raising an issue.
8
+ 2. Ensure any changes that change the behaviour or would be useful to implementers of this gem are documented within the README.md
9
+ 3. Increase the version number in any PR raised. The versioning scheme we use is [SemVer](https://semver.org/)
10
+
11
+ ## Code of Conduct
12
+
13
+ ### Our Pledge
14
+
15
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
16
+
17
+ ### Our Standards
18
+
19
+ Examples of behavior that contributes to creating a positive environment include:
20
+
21
+ - Using welcoming and inclusive language
22
+ - Being respectful of differing viewpoints and experiences
23
+ - Gracefully accepting constructive criticism
24
+ - Focusing on what is best for the community
25
+ - Showing empathy towards other community members
26
+
27
+ Examples of unacceptable behavior by participants include:
28
+
29
+ - The use of sexualized language or imagery and unwelcome sexual attention or advances
30
+ - Trolling, insulting/derogatory comments, and personal or political attacks
31
+ - Public or private harassment
32
+ - Publishing others' private information, such as a physical or electronic address, without explicit permission
33
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
34
+
35
+ ### Our Responsibilities
36
+
37
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
38
+
39
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
40
+
41
+ ### Scope
42
+
43
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
44
+
45
+ ### Enforcement
46
+
47
+ Instances of abusive, harassing or otherwise unacceptable behaviour may be reported by contacting the project team. The project team will decide how to respond to any compliants.
48
+
49
+ ### Attribution
50
+
51
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org/version/1/4), version 1.4, available at http://contributor-covenant.org/version/1/4
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,158 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ code_snippet (0.2.6)
5
+ clipboard
6
+ ffi
7
+ hashie
8
+ highline (~> 2.0)
9
+ logger (~> 1.4)
10
+ tty-prompt
11
+ tty-table
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ addressable (2.7.0)
17
+ public_suffix (>= 2.0.2, < 5.0)
18
+ ast (2.4.0)
19
+ axiom-types (0.1.1)
20
+ descendants_tracker (~> 0.0.4)
21
+ ice_nine (~> 0.11.0)
22
+ thread_safe (~> 0.3, >= 0.3.1)
23
+ bump (0.6.1)
24
+ byebug (11.0.1)
25
+ clipboard (1.3.5)
26
+ codeclimate-engine-rb (0.4.1)
27
+ virtus (~> 1.0)
28
+ coderay (1.1.2)
29
+ coercible (1.0.0)
30
+ descendants_tracker (~> 0.0.1)
31
+ descendants_tracker (0.0.4)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ diff-lcs (1.3)
34
+ docile (1.3.2)
35
+ equalizer (0.0.11)
36
+ erubis (2.7.0)
37
+ ffi (1.15.3)
38
+ flay (2.12.1)
39
+ erubis (~> 2.7.0)
40
+ path_expander (~> 1.0)
41
+ ruby_parser (~> 3.0)
42
+ sexp_processor (~> 4.0)
43
+ flog (4.6.3)
44
+ path_expander (~> 1.0)
45
+ ruby_parser (~> 3.1, > 3.1.0)
46
+ sexp_processor (~> 4.8)
47
+ hashie (4.1.0)
48
+ highline (2.0.3)
49
+ ice_nine (0.11.2)
50
+ jaro_winkler (1.5.4)
51
+ json (2.2.0)
52
+ launchy (2.4.3)
53
+ addressable (~> 2.3)
54
+ logger (1.4.3)
55
+ method_source (0.9.2)
56
+ parallel (1.19.1)
57
+ parser (2.5.3.0)
58
+ ast (~> 2.4.0)
59
+ pastel (0.8.0)
60
+ tty-color (~> 0.5)
61
+ path_expander (1.1.0)
62
+ pry (0.12.2)
63
+ coderay (~> 1.1.0)
64
+ method_source (~> 0.9.0)
65
+ public_suffix (4.0.1)
66
+ rainbow (3.0.0)
67
+ rake (13.0.1)
68
+ reek (4.8.2)
69
+ codeclimate-engine-rb (~> 0.4.0)
70
+ parser (>= 2.5.0.0, < 2.6)
71
+ rainbow (>= 2.0, < 4.0)
72
+ rspec (3.9.0)
73
+ rspec-core (~> 3.9.0)
74
+ rspec-expectations (~> 3.9.0)
75
+ rspec-mocks (~> 3.9.0)
76
+ rspec-core (3.9.0)
77
+ rspec-support (~> 3.9.0)
78
+ rspec-expectations (3.9.0)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.9.0)
81
+ rspec-mocks (3.9.0)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.9.0)
84
+ rspec-support (3.9.0)
85
+ rubocop (0.68.1)
86
+ jaro_winkler (~> 1.5.1)
87
+ parallel (~> 1.10)
88
+ parser (>= 2.5, != 2.5.1.1)
89
+ rainbow (>= 2.2.2, < 4.0)
90
+ ruby-progressbar (~> 1.7)
91
+ unicode-display_width (>= 1.4.0, < 1.6)
92
+ ruby-progressbar (1.10.1)
93
+ ruby_parser (3.14.1)
94
+ sexp_processor (~> 4.9)
95
+ rubycritic (3.5.2)
96
+ flay (~> 2.8)
97
+ flog (~> 4.4)
98
+ launchy (= 2.4.3)
99
+ parser (~> 2.5.0)
100
+ rainbow (~> 3.0)
101
+ reek (~> 4.4)
102
+ ruby_parser (~> 3.8)
103
+ tty-which (~> 0.3.0)
104
+ virtus (~> 1.0)
105
+ sexp_processor (4.13.0)
106
+ simplecov (0.17.1)
107
+ docile (~> 1.1)
108
+ json (>= 1.8, < 3)
109
+ simplecov-html (~> 0.10.0)
110
+ simplecov-html (0.10.2)
111
+ strings (0.2.1)
112
+ strings-ansi (~> 0.2)
113
+ unicode-display_width (>= 1.5, < 3.0)
114
+ unicode_utils (~> 1.4)
115
+ strings-ansi (0.2.0)
116
+ thread_safe (0.3.6)
117
+ tty-color (0.6.0)
118
+ tty-cursor (0.7.1)
119
+ tty-prompt (0.23.1)
120
+ pastel (~> 0.8)
121
+ tty-reader (~> 0.8)
122
+ tty-reader (0.9.0)
123
+ tty-cursor (~> 0.7)
124
+ tty-screen (~> 0.8)
125
+ wisper (~> 2.0)
126
+ tty-screen (0.8.1)
127
+ tty-table (0.12.0)
128
+ pastel (~> 0.8)
129
+ strings (~> 0.2.0)
130
+ tty-screen (~> 0.8)
131
+ tty-which (0.3.0)
132
+ unicode-display_width (1.5.0)
133
+ unicode_utils (1.4.0)
134
+ virtus (1.0.5)
135
+ axiom-types (~> 0.1)
136
+ coercible (~> 1.0)
137
+ descendants_tracker (~> 0.0, >= 0.0.3)
138
+ equalizer (~> 0.0, >= 0.0.9)
139
+ wisper (2.0.1)
140
+ yard (0.9.20)
141
+
142
+ PLATFORMS
143
+ ruby
144
+
145
+ DEPENDENCIES
146
+ bump (~> 0.6)
147
+ byebug (~> 11.0)
148
+ code_snippet!
149
+ pry (~> 0.11)
150
+ rake (~> 13.0)
151
+ rspec (~> 3.7, >= 3.7.0)
152
+ rubocop (~> 0.58)
153
+ rubycritic (~> 3.4, >= 3.4.0)
154
+ simplecov (~> 0.16)
155
+ yard (~> 0.9)
156
+
157
+ BUNDLED WITH
158
+ 2.2.16
data/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Andrew Bigger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # CodeSnippet
2
+
3
+ [![Ruby](https://github.com/andrewbigger/code_snippet/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/andrewbigger/code_snippet/actions/workflows/build.yml)
4
+
5
+ A code snippet handling tool that makes it easy to quickly access chunks of code.
6
+
7
+ ## Installation
8
+
9
+ Install the gem into your system:
10
+
11
+ ```bash
12
+ gem install code_snippet
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Before you begin
18
+
19
+ Before you use snippet, you need to set the `SNIPPET_DIR` environment variable to a path that contains your snippets:
20
+
21
+ ```bash
22
+ export SNIPPET_DIR="/Users/me/Code/snippets"
23
+ ```
24
+
25
+ ### Creating snippets
26
+
27
+ Snippets are just text files with the extension of the target language. For example, `for_i.go` might ontain a for loop.
28
+
29
+ The code does not need to compile or be able to be interpreted for it to be displayed by snippet, it should be content that's easy to paste into the project you're currently working on.
30
+
31
+ ### Listing and Viewing Snippets
32
+
33
+ Once you have a set of snippets, run `snippet list` to show a list of all your snippets:
34
+
35
+ ```bash
36
+ $ snippet list
37
+
38
+ +---------------------+----+-----------------------------------------------------------------+
39
+ |NAME |LANG|PATH |
40
+ +---------------------+----+-----------------------------------------------------------------+
41
+ |for_i |.go |/Users/me/Code/templates/snippets/golang/for_i.go |
42
+ |table_test |.go |/Users/me/Code/templates/snippets/golang/table_test.go |
43
+ +---------------------+----+-----------------------------------------------------------------+
44
+ ```
45
+
46
+ You can then show a snippet by executing `snippet show <name>`:
47
+
48
+ ```bash
49
+ $ snippet show for_i
50
+
51
+ for 1 := 1; i < 10; i++ {
52
+ // do something
53
+ }
54
+ ```
55
+
56
+ You can copy the snippet straight to the clipboard by adding the `-c=true` to the end of the command.
57
+
58
+ ## Tests and Quality
59
+
60
+ Tests cover this project and are written in RSpec. You'll find them in the spec folder.
61
+
62
+ ```bash
63
+ bundle exec rspec spec
64
+ ```
65
+
66
+ Tests and quality tasks are included in the default rake task which can be run thus:
67
+
68
+ ```bash
69
+ bundle exec rake
70
+ ```
71
+
72
+ ## Contributing
73
+
74
+ See CONTRIBUTING.md for more information
75
+
76
+ ## Licence
77
+
78
+ This gem is covered by the terms of the MIT licence. See LICENCE for more information
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'bump/tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+ require 'rubycritic/rake_task'
6
+ require 'yard'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ RuboCop::RakeTask.new
10
+
11
+ RubyCritic::RakeTask.new do |task|
12
+ task.paths = FileList['lib/**/*.rb'] - FileList['spec/**/*_spec.rb']
13
+ task.options = '--no-browser --path ./target/reports/critique'
14
+ end
15
+
16
+ YARD::Rake::YardocTask.new
17
+
18
+ task default: %i[spec rubocop rubycritic yard]
data/bin/snippet ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(__dir__ + '/../lib')
4
+
5
+ require 'rubygems'
6
+ require 'optparse'
7
+ require 'highline'
8
+
9
+ require 'code_snippet'
10
+ require 'code_snippet/cli'
11
+
12
+ USAGE = "Snippet is a CLI tool for quick access to code snippets
13
+
14
+ Usage:\tsnippet <command> <variables> <opts>
15
+ Options:
16
+ \s\s\s\s--trace\t\t trace mode on
17
+ -l, --language\t snippet language filter
18
+ -c, --copy\t\t copy snippet to clipboard
19
+
20
+ -h, --help\t\t print usage
21
+
22
+ Commands:
23
+ show\t\t\t finds and shows snippet
24
+ list\t\t\t displays a list of snippets
25
+
26
+ path\t\t\t prints configured SNIPPET_DIR
27
+ version\t\t prints gem version
28
+ ".freeze
29
+
30
+ @trace = false
31
+ @overwrite = false
32
+
33
+ OptionParser.new do |opts|
34
+ opts.banner = USAGE
35
+ opts.on('--trace') { @trace = true }
36
+
37
+ opts.on('-l', '--language STRING') { |l| @lang = l }
38
+ opts.on('-c', '--copy BOOL') { @copy = true }
39
+
40
+ opts.on_tail('-h', '--help') do
41
+ CodeSnippet::CLI.print_message_and_exit(USAGE)
42
+ end
43
+ end.parse!
44
+
45
+ begin
46
+ raise 'ERROR: no command provided' unless ARGV[0]
47
+
48
+ cmd = ARGV.shift
49
+ CodeSnippet::CLI::Commands.public_send(
50
+ cmd.to_sym,
51
+ @lang,
52
+ !@copy.nil?,
53
+ ARGV
54
+ )
55
+ rescue StandardError => e
56
+ CodeSnippet::CLI.print_message(e)
57
+ CodeSnippet::CLI.print_message(e.backtrace) if @trace
58
+ CodeSnippet::CLI.print_message("\n")
59
+ CodeSnippet::CLI.print_message_and_exit(USAGE)
60
+ end
61
+
62
+ exit(0)
@@ -0,0 +1,18 @@
1
+ image: ruby:2.6.4
2
+
3
+ pipelines:
4
+ branches:
5
+ master:
6
+ - step:
7
+ name: Build and Test
8
+ caches:
9
+ - bundler
10
+ script:
11
+ - gem install bundler
12
+ - bundle install --path .bundle
13
+ - bundle exec rake
14
+ deployment: production
15
+
16
+ definitions:
17
+ caches:
18
+ bundler: .bundle
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'code_snippet/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'code_snippet'
9
+ spec.version = CodeSnippet::VERSION
10
+ spec.authors = ['Andrew Bigger']
11
+ spec.email = ['andrew.bigger@gmail.com']
12
+ spec.summary = 'A code snippet handling tool'
13
+ spec.homepage = 'https://github.com/andrewbigger/code_snippet'
14
+ spec.license = 'Private'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'clipboard'
22
+ spec.add_dependency 'ffi'
23
+ spec.add_dependency 'hashie'
24
+ spec.add_dependency 'highline', '~> 2.0'
25
+ spec.add_dependency 'logger', '~> 1.4'
26
+ spec.add_dependency 'tty-prompt'
27
+ spec.add_dependency 'tty-table'
28
+
29
+ spec.add_development_dependency 'bump', '~> 0.6'
30
+ spec.add_development_dependency 'byebug', '~> 11.0'
31
+ spec.add_development_dependency 'pry', '~> 0.11'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.58'
35
+ spec.add_development_dependency 'rubycritic', '~> 3.4', '>= 3.4.0'
36
+ spec.add_development_dependency 'simplecov', '~> 0.16'
37
+ spec.add_development_dependency 'yard', '~> 0.9'
38
+ end
@@ -0,0 +1,82 @@
1
+ require 'clipboard'
2
+
3
+ module CodeSnippet
4
+ # Command line interface helpers and actions
5
+ module CLI
6
+ # CLI Actions
7
+ module Commands
8
+ ##
9
+ # Show displays a snippet
10
+ #
11
+ def self.show(
12
+ lang,
13
+ copy,
14
+ args = []
15
+ )
16
+ name = args.first
17
+ snippet_dir = CodeSnippet::CLI.snip_dir
18
+
19
+ manager = CodeSnippet::Manager.new(snippet_dir)
20
+ manager.load_snippets
21
+
22
+ snips = manager.find(name, lang)
23
+ raise "unable to find #{name}" if snips.empty?
24
+
25
+ snip = snips.first
26
+ if snips.length > 1
27
+ snip = CLI::Presenters.pick_from(
28
+ 'Multiple snippets found, which one would you like to view?',
29
+ snips
30
+ )
31
+ end
32
+
33
+ if copy
34
+ Clipboard.copy(snip.content)
35
+ CLI.print_message("COPIED: #{snip.path}")
36
+ end
37
+
38
+ CLI::Presenters.show(snip)
39
+ end
40
+
41
+ ##
42
+ # List lists snippets
43
+ #
44
+ def self.list(
45
+ lang,
46
+ _copy,
47
+ _args = []
48
+ )
49
+ snippet_dir = CodeSnippet::CLI.snip_dir
50
+
51
+ manager = CodeSnippet::Manager.new(snippet_dir)
52
+ manager.load_snippets
53
+
54
+ snippets = lang ? manager.filter_by_extension(lang) : manager.snippets
55
+
56
+ CLI::Presenters.list_snippets(snippets)
57
+ end
58
+
59
+ ##
60
+ # Show snippet directory path
61
+ #
62
+ def self.path(
63
+ _lang,
64
+ _copy,
65
+ _args = []
66
+ )
67
+ CLI.print_message(CLI.snip_dir)
68
+ end
69
+
70
+ ##
71
+ # Show snippet gem version
72
+ #
73
+ def self.version(
74
+ _lang,
75
+ _copy,
76
+ _args = []
77
+ )
78
+ CLI.print_message(CodeSnippet::VERSION)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,42 @@
1
+ require 'tty-table'
2
+ require 'tty-prompt'
3
+
4
+ module CodeSnippet
5
+ # Command line interface helpers and actions
6
+ module CLI
7
+ # CLI Presentation functions
8
+ module Presenters
9
+ def self.pick_from(question, snips)
10
+ prompt = TTY::Prompt.new
11
+
12
+ choice = prompt.select(
13
+ question,
14
+ snips.map(&:path)
15
+ )
16
+
17
+ snips.find { |snip| snip.path == choice }
18
+ end
19
+
20
+ def self.show(snip)
21
+ CLI.print_message(snip.content)
22
+ end
23
+
24
+ def self.list_snippets(snippets)
25
+ result_header = %w[NAME LANG PATH]
26
+
27
+ results = TTY::Table.new(
28
+ result_header,
29
+ snippets.map do |snippet|
30
+ [
31
+ snippet.name,
32
+ snippet.ext,
33
+ snippet.path
34
+ ]
35
+ end
36
+ )
37
+
38
+ CLI.print_message(results.render(:ascii))
39
+ end
40
+ end
41
+ end
42
+ end