tty-prompt-files 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 636af1123ad9f1e4a01854b9d5d22c228a3606b49b953c8f8b5bfd7e83bd59ac
4
- data.tar.gz: 0fd01831f754ba9fa4627c7de07ac061705535b2bdacf41407f974d73cf0f2af
3
+ metadata.gz: decb98e79f33422b8f80a7d897aab213616a4be58386bd684051f098b19df478
4
+ data.tar.gz: 16b548ace6a793787cde6fb51038da64e60599f0d05ddd60ab83b2177cdb6ed2
5
5
  SHA512:
6
- metadata.gz: 34d8e7b77e6678167986cf196354b3fae725968ce232d2952ddc1faaf65b4de992f4d44a623dcdcd12e9ce24175c9e212178c04bbe0bde246df20a2778c3ef10
7
- data.tar.gz: c2a8e4d2d6827238223281bcd5cd90a352155e4e3f109a05e345ba2db7c63412bfd55e75d026288b4d0abe7d1799e205ca447e76b41066c6c9b2778459443bec
6
+ metadata.gz: df871fd53f0af611e845350fc6f5da19a081cc7bf554e5086785ffa3bf9f69b9f3d1de9471ed23d429be5a8239eacfa92f17c626583b4a2302a46567a4f06ff7
7
+ data.tar.gz: df13e2ed0120ff6043b5130f4dc5aceae40944ff427025f8a88790c009d076780b405b969b149d174fe95ac8f70ef1676f7c6b8721955a6d64f0c443a8c6bb20
data/Gemfile CHANGED
@@ -4,13 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in tty-prompt-files.gemspec
6
6
  gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- group :test do
11
- gem "rspec", "~> 3.0"
12
- end
13
-
14
- group :development do
15
- gem "pry", "~> 0.14.1"
16
- end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tty-prompt-files (0.1.0)
4
+ tty-prompt-files (1.0.0)
5
5
  tty-prompt (~> 0.23.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,30 +1,34 @@
1
1
  # TTY::Prompt::Files
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ TTY-Prompt-files is extension for [tty-prompt](https://github.com/piotrmurach/tty-prompt) gem that allow interactive selection elements from file system and get absolute path.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tty/prompt/files`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Note!
6
6
 
7
- ## Installation
7
+ Be careful to use library before first major version. It does not support backward compatibility.
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
9
+ ## Usage
14
10
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
11
+ ```rb
12
+ require 'tty-prompt-files'
16
13
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+ prompt = TTY::Prompt.new
18
15
 
19
- ## Usage
16
+ prompt.select_element_from_file_system
17
+ ```
20
18
 
21
- TODO: Write usage instructions here
19
+ After element is selected, output will be a element full path.
22
20
 
23
- ## Development
21
+ `select_element_from_file_system` has 5 parameters:
24
22
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+ ```rb
24
+ prompt.select_element_from_file_system(text: "", pattern: "*", path: ".", multi_select: false, **options)
25
+ ```
26
26
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+ `text` is text user will see along with elements. By default: `""`.\
28
+ `pattern` is determining for what file will be output based on matching the pattern. If you want to display hidden files, use `"{.[^\.]*,*}"` pattern. By default: `"*"`.\
29
+ `path` is determining path of the directory, can be relative or absolute. By default: `"."`.\
30
+ `multi_select` refers to original [API](https://github.com/piotrmurach/tty-prompt?tab=readme-ov-file#263-multi_select). By default: `false`.
31
+ `**options` you can add any params from original [API](https://github.com/piotrmurach/tty-prompt?tab=readme-ov-file#2621-cycle). No default value.\
28
32
 
29
33
  ## Contributing
30
34
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Files
5
- VERSION = "0.1.1"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
data/lib/tty/files.rb CHANGED
@@ -1,26 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "files/version"
4
- require "pry"
5
4
 
6
5
  module TTY
7
6
  class Prompt
8
- def select_element_from_file_system(pattern: "*", path: ".", text: "", options: {})
7
+ def select_element_from_file_system(text: "", pattern: "*", path: ".", multi_select: false, **options)
9
8
  pathnames = get_pathnames_from_path(pattern, path)
10
9
 
11
10
  file_names = pathnames.map do |pathname|
12
11
  pathname.basename.to_s
13
12
  end
14
13
 
15
- selected_element = self.select(text, file_names)
14
+ unless multi_select
15
+ selected_element = self.select(text, file_names, **options)
16
16
 
17
- get_selected_element_full_path(pathnames, selected_element)
17
+ return get_selected_element_full_path(pathnames, selected_element)
18
+ end
19
+
20
+ selected_elements = self.multi_select(text, file_names, **options)
21
+
22
+ selected_elements.map do |selected_element|
23
+ get_selected_element_full_path(pathnames, selected_element)
24
+ end
18
25
  end
19
26
 
20
27
  private
21
28
 
22
29
  def get_pathnames_from_path(pattern, path)
23
- pathnames = Pathname.glob(path + "/" + pattern)
30
+ if path[-1] != "/"
31
+ pathnames = Pathname.glob(path + "/" + pattern)
32
+ else
33
+ pathnames = Pathname.glob(path + pattern)
34
+ end
24
35
 
25
36
  pathnames.map(&:realpath)
26
37
  end
@@ -0,0 +1 @@
1
+ require_relative 'tty/files'
@@ -29,4 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "tty-prompt", "~> 0.23.1"
32
+
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "pry", "~> 0.14.1"
32
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-prompt-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Set27
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-11 00:00:00.000000000 Z
11
+ date: 2024-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.23.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.1
27
69
  description:
28
70
  email:
29
71
  - matvei.traz@gmail.com
@@ -39,6 +81,7 @@ files:
39
81
  - LICENSE.txt
40
82
  - README.md
41
83
  - Rakefile
84
+ - lib/tty-prompt-files.rb
42
85
  - lib/tty/files.rb
43
86
  - lib/tty/files/version.rb
44
87
  - sig/tty/prompt/files.rbs