tty-prompt-files 0.1.0 → 0.1.2

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: b8e926771cdbb07ecd05984c8398d204d36c8e2633e90af325bf4f2eb6b2263c
4
- data.tar.gz: 400036a895ee673b560673f9086a405cf2b5d10a0b83a122804d6e0b68848c3a
3
+ metadata.gz: 03ad940e0f61e4ec12aa0a7e6ff3129032ab6f8a4b58b732a36cd6c37f733270
4
+ data.tar.gz: c4697eb80dcfde2842b315d86d7e01648be2f0728a7d10256e09da88711b9517
5
5
  SHA512:
6
- metadata.gz: 576330ec6293696871efb6d707329b73f1c4497f7f1dda154cdeac3e909ea9e6e4c7708c190044f5c0a8508b191a8aaada9fb09917061954ce7d30bd678a9939
7
- data.tar.gz: 3b677a25f715cf4db500bb310b070d02c68f93a7687a8a98788a016eb2c6a7e5167778c3b2fcb933f48bbc888a57f07d7723964f02a8e2de765bc778a2a28f36
6
+ metadata.gz: bad1f62287c1a86878545bd02a6777052de7c93ec6ad406597599a04c549d8edf6e7b5966cc2750a14307736fcad5e02cd7f160617aa7349459e24f3c3d7c818
7
+ data.tar.gz: 332763db0a964bc461701122b84bf82f71ea015317c982c7031690fb88a72f4f2d7bfb611ba9a79126c81ddc666e754e914d636de108dc5c0ad7ab519a0ae33a
data/CHANGELOG.md CHANGED
@@ -3,3 +3,7 @@
3
3
  ## [0.1.0] - 2024-07-28
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.1] - 2024-08-11
8
+
9
+ - Fix `select_element_from_file_system` for non default location
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 (0.1.1)
5
5
  tty-prompt (~> 0.23.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,30 +1,30 @@
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
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
9
+ ## Usage
16
10
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
11
+ ```rb
12
+ prompt = TTY::Prompt.new
18
13
 
19
- ## Usage
14
+ prompt.select_element_from_file_system
15
+ ```
20
16
 
21
- TODO: Write usage instructions here
17
+ After element is selected, output will be a element full path.
22
18
 
23
- ## Development
19
+ `select_element_from_file_system` has 3 parameters:
24
20
 
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.
21
+ ```rb
22
+ prompt.select_element_from_file_system(pattern: "*", path: ".", text: "")
23
+ ```
26
24
 
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).
25
+ `pattern` is determining for what file will be output based on matching the pattern. If you want to display hidden files, use `"{.[^\.]*,*}"` pattern.\
26
+ `path` is determining path of the directory, can be relative or absolute. **Note**: relative **should not** end with `/`.\
27
+ `text` is text user will see along with elements.
28
28
 
29
29
  ## Contributing
30
30
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Files
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
data/lib/tty/files.rb CHANGED
@@ -4,18 +4,30 @@ require_relative "files/version"
4
4
 
5
5
  module TTY
6
6
  class Prompt
7
- def select_element_from_file_system(pattern: "*", path: ".", text: "", options: {})
8
- elements = get_all_elements_from_path(pattern, path)
7
+ def files(pattern: "*", path: ".", text: "", options: {})
8
+ pathnames = get_pathnames_from_path(pattern, path)
9
9
 
10
- selected_element = self.select(text, elements)
10
+ file_names = pathnames.map do |pathname|
11
+ pathname.basename.to_s
12
+ end
11
13
 
12
- selected_element.realpath.to_path
14
+ selected_element = self.select(text, file_names)
15
+
16
+ get_selected_element_full_path(pathnames, selected_element)
13
17
  end
14
18
 
15
19
  private
16
20
 
17
- def get_all_elements_from_path(pattern, path)
18
- Pathname.glob(pattern, base: path)
21
+ def get_pathnames_from_path(pattern, path)
22
+ pathnames = Pathname.glob(path + "/" + pattern)
23
+
24
+ pathnames.map(&:realpath)
25
+ end
26
+
27
+ def get_selected_element_full_path(pathnames, selected_element)
28
+ selected_element_pathname = pathnames.find { |pathname| pathname.basename.to_s == selected_element }
29
+
30
+ selected_element_pathname.realpath.to_s
19
31
  end
20
32
  end
21
33
  end
@@ -0,0 +1 @@
1
+ require_relative 'tty/files'
@@ -29,10 +29,4 @@ 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
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
35
-
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
38
32
  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.0
4
+ version: 0.1.2
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-08 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt
@@ -39,6 +39,7 @@ files:
39
39
  - LICENSE.txt
40
40
  - README.md
41
41
  - Rakefile
42
+ - lib/tty-prompt-files.rb
42
43
  - lib/tty/files.rb
43
44
  - lib/tty/files/version.rb
44
45
  - sig/tty/prompt/files.rbs