planter-cli 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +10 -0
  5. data/README.md +5 -3
  6. data/bin/plant +1 -1
  7. data/docker/Dockerfile +2 -4
  8. data/docker/Dockerfile-2.6 +3 -5
  9. data/docker/Dockerfile-2.7 +2 -4
  10. data/docker/Dockerfile-3.0 +2 -3
  11. data/docker/Dockerfile-3.3 +11 -0
  12. data/docker/sources.list +11 -0
  13. data/lib/planter/filelist.rb +5 -4
  14. data/lib/planter/plant.rb +3 -3
  15. data/lib/planter/prompt.rb +5 -5
  16. data/lib/planter/string.rb +22 -0
  17. data/lib/planter/tag.rb +39 -2
  18. data/lib/planter/version.rb +1 -1
  19. data/lib/planter.rb +30 -17
  20. data/lib/tty-spinner/.editorconfig +9 -0
  21. data/lib/tty-spinner/.github/FUNDING.yml +1 -0
  22. data/lib/tty-spinner/.github/ISSUE_TEMPLATE/BUG_REPORT.md +31 -0
  23. data/lib/tty-spinner/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +23 -0
  24. data/lib/tty-spinner/.github/ISSUE_TEMPLATE/config.yml +5 -0
  25. data/lib/tty-spinner/.github/PULL_REQUEST_TEMPLATE.md +19 -0
  26. data/lib/tty-spinner/.github/workflows/ci.yml +59 -0
  27. data/lib/tty-spinner/.gitignore +14 -0
  28. data/lib/tty-spinner/.rspec +2 -0
  29. data/lib/tty-spinner/.rubocop.yml +78 -0
  30. data/lib/tty-spinner/CHANGELOG.md +151 -0
  31. data/lib/tty-spinner/CODE_OF_CONDUCT.md +132 -0
  32. data/lib/tty-spinner/Gemfile +17 -0
  33. data/lib/tty-spinner/LICENSE.txt +22 -0
  34. data/lib/tty-spinner/README.md +581 -0
  35. data/lib/tty-spinner/Rakefile +10 -0
  36. data/lib/tty-spinner/appveyor.yml +33 -0
  37. data/lib/tty-spinner/bin/console +14 -0
  38. data/lib/tty-spinner/bin/setup +8 -0
  39. data/lib/tty-spinner/demo.gif +0 -0
  40. data/lib/tty-spinner/examples/auto_spin.rb +10 -0
  41. data/lib/tty-spinner/examples/basic.rb +10 -0
  42. data/lib/tty-spinner/examples/clear.rb +11 -0
  43. data/lib/tty-spinner/examples/color.rb +14 -0
  44. data/lib/tty-spinner/examples/error.rb +11 -0
  45. data/lib/tty-spinner/examples/formats.rb +13 -0
  46. data/lib/tty-spinner/examples/hide_cursor.rb +14 -0
  47. data/lib/tty-spinner/examples/log.rb +13 -0
  48. data/lib/tty-spinner/examples/multi/basic.rb +15 -0
  49. data/lib/tty-spinner/examples/multi/basic_top_level.rb +15 -0
  50. data/lib/tty-spinner/examples/multi/custom_style.rb +28 -0
  51. data/lib/tty-spinner/examples/multi/files.rb +16 -0
  52. data/lib/tty-spinner/examples/multi/jobs.rb +11 -0
  53. data/lib/tty-spinner/examples/multi/multi.rb +19 -0
  54. data/lib/tty-spinner/examples/multi/multi_top_level.rb +20 -0
  55. data/lib/tty-spinner/examples/multi/pause.rb +28 -0
  56. data/lib/tty-spinner/examples/multi/threaded.rb +30 -0
  57. data/lib/tty-spinner/examples/pause.rb +24 -0
  58. data/lib/tty-spinner/examples/run.rb +20 -0
  59. data/lib/tty-spinner/examples/success.rb +11 -0
  60. data/lib/tty-spinner/examples/threaded.rb +13 -0
  61. data/lib/tty-spinner/examples/update.rb +13 -0
  62. data/lib/tty-spinner/lib/tty/spinner/formats.rb +274 -0
  63. data/lib/tty-spinner/lib/tty/spinner/multi.rb +352 -0
  64. data/lib/tty-spinner/lib/tty/spinner/version.rb +7 -0
  65. data/lib/tty-spinner/lib/tty/spinner.rb +604 -0
  66. data/lib/tty-spinner/lib/tty-spinner.rb +2 -0
  67. data/lib/tty-spinner/spec/spec_helper.rb +52 -0
  68. data/lib/tty-spinner/spec/unit/auto_spin_spec.rb +25 -0
  69. data/lib/tty-spinner/spec/unit/clear_spec.rb +16 -0
  70. data/lib/tty-spinner/spec/unit/error_spec.rb +53 -0
  71. data/lib/tty-spinner/spec/unit/events_spec.rb +35 -0
  72. data/lib/tty-spinner/spec/unit/formats_spec.rb +9 -0
  73. data/lib/tty-spinner/spec/unit/frames_spec.rb +31 -0
  74. data/lib/tty-spinner/spec/unit/hide_cursor_spec.rb +51 -0
  75. data/lib/tty-spinner/spec/unit/job_spec.rb +12 -0
  76. data/lib/tty-spinner/spec/unit/join_spec.rb +10 -0
  77. data/lib/tty-spinner/spec/unit/log_spec.rb +60 -0
  78. data/lib/tty-spinner/spec/unit/multi/auto_spin_spec.rb +32 -0
  79. data/lib/tty-spinner/spec/unit/multi/error_spec.rb +107 -0
  80. data/lib/tty-spinner/spec/unit/multi/line_inset_spec.rb +57 -0
  81. data/lib/tty-spinner/spec/unit/multi/on_spec.rb +11 -0
  82. data/lib/tty-spinner/spec/unit/multi/register_spec.rb +46 -0
  83. data/lib/tty-spinner/spec/unit/multi/spin_spec.rb +101 -0
  84. data/lib/tty-spinner/spec/unit/multi/stop_spec.rb +95 -0
  85. data/lib/tty-spinner/spec/unit/multi/success_spec.rb +108 -0
  86. data/lib/tty-spinner/spec/unit/new_spec.rb +25 -0
  87. data/lib/tty-spinner/spec/unit/pause_spec.rb +43 -0
  88. data/lib/tty-spinner/spec/unit/reset_spec.rb +19 -0
  89. data/lib/tty-spinner/spec/unit/run_spec.rb +30 -0
  90. data/lib/tty-spinner/spec/unit/spin_spec.rb +117 -0
  91. data/lib/tty-spinner/spec/unit/stop_spec.rb +88 -0
  92. data/lib/tty-spinner/spec/unit/success_spec.rb +53 -0
  93. data/lib/tty-spinner/spec/unit/tty_spec.rb +8 -0
  94. data/lib/tty-spinner/spec/unit/update_spec.rb +85 -0
  95. data/lib/tty-spinner/tasks/console.rake +11 -0
  96. data/lib/tty-spinner/tasks/coverage.rake +11 -0
  97. data/lib/tty-spinner/tasks/spec.rake +29 -0
  98. data/lib/tty-spinner/tty-spinner.gemspec +36 -0
  99. data/scripts/runtests.sh +1 -1
  100. data/spec/cli_spec.rb +27 -0
  101. data/spec/spec_helper.rb +26 -0
  102. data/spec/templates/test/_planter.yml +3 -6
  103. data/src/_README.md +5 -3
  104. metadata +86 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b4906c83392316be6ac61380bd0d2401a847f4c08f6afc91bdfbd4858980568
4
- data.tar.gz: 7253e2ec572be45e7543d82ad2b1dde685fc5b8ba7b256ec914b0575e44ad507
3
+ metadata.gz: a4b54e16d9836121fd1fa5831a1c7433056f45e9372b9985640a6052a2852aab
4
+ data.tar.gz: d2a57bd628c33f9dcccdc605577a11e4aaacbeef3a0c261f96835771f8fc0223
5
5
  SHA512:
6
- metadata.gz: 98fd1c334e3d2efdcdc10171d7a5b5f81898e9a03890bc08cd65e2f3c8a10941cfe46e5e5b23584f28c87aad3b85471ab544c3665049c5abfd911006b40bfbe8
7
- data.tar.gz: a7a86edaf7bf49cb65cde877ab4aec8bd92a6f27a90c09f526e50f9f1ddc84c27655e67bfea75b9463c8033601ae1961e4854bce76f4e268bfe87aa3171c7677
6
+ metadata.gz: 0001cffb09df38704dbeadb6b68b42418a0b02741430fd3932fcdf845d53052945d1e51dd5bd6227c8f02cd70fbbd86f8d037bd1ef2da7547c5ae3f859320a93
7
+ data.tar.gz: b612aa38f0aaa7d1746b8715e032e93550735510b9e0e5f90cbdaef35d0cb0eea3f9afbc8c1f001f03eb40c0de41f7773e5ef7f4799e1792a4543be36ff4074b
data/.gitignore CHANGED
@@ -45,3 +45,4 @@ Gemfile.lock
45
45
  .history
46
46
  spec/test/
47
47
  spec/noop
48
+ bundle
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "lib/planter/tty-spinner"]
2
+ path = lib/planter/tty-spinner
3
+ url = git@github.com:piotrmurach/tty-spinner.git
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 3.0.2
2
+
3
+ 2024-09-01 09:46
4
+
5
+ #### IMPROVED
6
+
7
+ - Add basic CLI tests
8
+ - Better debug output and output of info messages above spinner
9
+ - Handle Bash-style globs in file: filenames
10
+
1
11
  ### 3.0.1
2
12
 
3
13
  2024-08-31 14:19
data/README.md CHANGED
@@ -27,9 +27,9 @@ git_init: false
27
27
  preserve_tags: true
28
28
  ```
29
29
 
30
- ### Scripts.
30
+ ### Scripts
31
31
 
32
- Scripts for execution after planting can be stored in `~/.config/planter/scripts` and referenced by filename only. Alternatively, scripts may be stored within a template in a `_scritps` subfolder.
32
+ Scripts for execution after planting can be stored in `~/.config/planter/scripts` and referenced by filename only. Alternatively, scripts may be stored within a template in a `_scripts` subfolder.
33
33
 
34
34
  Scripts can be executable files in any language, and receive the template directory and the planted directory as arguments $1 and $2.
35
35
 
@@ -74,6 +74,8 @@ files:
74
74
  "%%title%%.md": overwrite
75
75
  ```
76
76
 
77
+ Filenames can include wildcards (`*`, `?`), and Bash-style globbing (`[0-9]`, `[a-z]`, `{one,two,three}`).
78
+
77
79
  If `merge` is specified, then the source file is scanned for merge comments and those are merged if they don't exist in the copied/existing file. If no merge comments are defined, then the entire contents of the source file are appended to the destination file (unless the file already matches the source). Merge comments start with `merge` and end with `/merge` and can have any comment syntax preceding them, for example:
78
80
 
79
81
  ```
@@ -104,7 +106,7 @@ replacements:
104
106
  "(main|app)\.js": "%%script:lower%%.js"
105
107
  ```
106
108
 
107
- Replacements are performed on both file/directory names and file contents.
109
+ Replacements are performed on both file/directory names and file contents. This is especially handy when the source of the plant is a Git repo, allowing the replacement of elements without having to create %%templated%% filenames and contents.
108
110
 
109
111
  ### Finder Tags
110
112
 
data/bin/plant CHANGED
@@ -105,7 +105,7 @@ elsif ARGV.count.zero?
105
105
  end
106
106
 
107
107
  ARGV.each do |template|
108
- Planter.spinner.update(title: 'Initializing configuration')
108
+ # Planter.spinner.update(title: 'Initializing configuration')
109
109
  Planter.config = template
110
110
  app = Planter::Plant.new
111
111
  app.plant
data/docker/Dockerfile CHANGED
@@ -1,12 +1,10 @@
1
1
  FROM ruby:3.0.1
2
- # RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
3
2
  RUN mkdir /planter
4
3
  WORKDIR /planter
5
-
6
4
  RUN gem install bundler:2.2.29
7
- RUN apt-get update -y
5
+ COPY ./docker/sources.list /etc/apt/sources.list
6
+ RUN apt-get update -y --allow-insecure-repositories || true
8
7
  RUN apt-get install -y less vim
9
8
  COPY ./docker/inputrc /root/.inputrc
10
9
  COPY ./docker/bash_profile /root/.bash_profile
11
- RUN mkdir -p /root/.config/planter/templates/test
12
10
  CMD ["/planter/scripts/runtests.sh"]
@@ -1,12 +1,10 @@
1
1
  FROM ruby:2.6
2
- # RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
3
2
  RUN mkdir /planter
4
3
  WORKDIR /planter
5
- # COPY ./ /planter/
6
4
  RUN gem install bundler:2.2.29
7
- # RUN apt-get update -y
8
- # RUN apt-get install -y less vim
5
+ COPY ./docker/sources.list /etc/apt/sources.list
6
+ RUN apt-get update -y --allow-insecure-repositories || true
7
+ RUN apt-get install -y less vim
9
8
  COPY ./docker/inputrc /root/.inputrc
10
9
  COPY ./docker/bash_profile /root/.bash_profile
11
- RUN mkdir -p /root/.config/planter/templates/test
12
10
  CMD ["/planter/scripts/runtests.sh"]
@@ -1,12 +1,10 @@
1
1
  FROM ruby:2.7
2
- # RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
3
2
  RUN mkdir /planter
4
3
  WORKDIR /planter
5
- # COPY ./ /planter/
6
4
  RUN gem install bundler:2.2.29
7
- RUN apt-get update -y
5
+ COPY ./docker/sources.list /etc/apt/sources.list
6
+ RUN apt-get update -y --allow-insecure-repositories || true
8
7
  RUN apt-get install -y less vim
9
8
  COPY ./docker/inputrc /root/.inputrc
10
9
  COPY ./docker/bash_profile /root/.bash_profile
11
- RUN mkdir -p /root/.config/planter/templates/test
12
10
  CMD ["/planter/scripts/runtests.sh"]
@@ -1,10 +1,9 @@
1
1
  FROM ruby:3.0.0
2
- # RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
3
2
  RUN mkdir /planter
4
3
  WORKDIR /planter
5
- # COPY ./ /planter/
6
4
  RUN gem install bundler:2.2.29
7
- RUN apt-get update -y
5
+ COPY ./docker/sources.list /etc/apt/sources.list
6
+ RUN apt-get update -y --allow-insecure-repositories || true
8
7
  RUN apt-get install -y less vim
9
8
  COPY ./docker/inputrc /root/.inputrc
10
9
  COPY ./docker/bash_profile /root/.bash_profile
@@ -0,0 +1,11 @@
1
+ FROM ruby:3.3.0
2
+ # RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
3
+ RUN mkdir /planter
4
+ WORKDIR /planter
5
+ RUN gem install bundler:2.2.29
6
+ COPY ./docker/sources.list /etc/apt/sources.list
7
+ RUN apt-get update -y --allow-insecure-repositories || true
8
+ RUN apt-get install -y less vim
9
+ COPY ./docker/inputrc /root/.inputrc
10
+ COPY ./docker/bash_profile /root/.bash_profile
11
+ CMD ["/planter/scripts/runtests.sh"]
@@ -0,0 +1,11 @@
1
+ deb http://archive.ubuntu.com/ubuntu/ focal main restricted
2
+ deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
3
+ deb http://archive.ubuntu.com/ubuntu/ focal universe
4
+ deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
5
+ deb http://archive.ubuntu.com/ubuntu/ focal multiverse
6
+ deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
7
+ deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
8
+
9
+ deb http://security.ubuntu.com/ubuntu focal-security main restricted
10
+ deb http://security.ubuntu.com/ubuntu focal-security universe
11
+ deb http://security.ubuntu.com/ubuntu focal-security multiversesudo apt update
@@ -39,7 +39,7 @@ module Planter
39
39
  handle_operator(file)
40
40
  end
41
41
  rescue StandardError => e
42
- Planter.notify("#{e}\n#{e.backtrace}", :debug)
42
+ Planter.notify("#{e}\n#{e.backtrace}", :debug, above_spinner: true)
43
43
  Planter.notify('Error copying files/directories', :error, exit_code: 128)
44
44
  end
45
45
 
@@ -141,7 +141,8 @@ module Planter
141
141
  # If there are any merge sections left, merge them with the target file
142
142
  if merges.count.positive?
143
143
  File.open(entry.target, 'w') { |f| f.puts "#{target_content.chomp}\n\n#{merges.join("\n\n")}" }
144
- Planter.notify("Merged #{entry.file} => #{entry.target} (#{merges.count} merges)", :debug)
144
+ Planter.notify("[Merged] #{entry.file} => #{entry.target} (#{merges.count} merges)", :debug,
145
+ above_spinner: true)
145
146
  else
146
147
  # If there are no merge sections left, copy the file instead
147
148
  copy_file(entry)
@@ -166,12 +167,12 @@ module Planter
166
167
  # Copy the file if it isn't a directory
167
168
  FileUtils.cp(file.file, file.target) unless File.directory?(file.file)
168
169
  # Log a message to the console
169
- Planter.notify("Copied #{file.file} => #{file.target}", :debug)
170
+ Planter.notify("[Copied] #{file.file} => #{file.target}", :debug, above_spinner: true)
170
171
  # Return true to indicate success
171
172
  true
172
173
  else
173
174
  # Log a message to the console
174
- Planter.notify("Skipped #{file.file} => #{file.target}", :debug)
175
+ Planter.notify("[Skipped] #{file.file} => #{file.target}", :debug, above_spinner: true)
175
176
  # Return false to indicate that the copy was skipped
176
177
  false
177
178
  end
data/lib/planter/plant.rb CHANGED
@@ -187,14 +187,14 @@ module Planter
187
187
  new_content.gsub!(%r{^.{.4}/?merge *.{,4}\n}, '') if new_content =~ /^.{.4}merge *\n/
188
188
 
189
189
  unless content == new_content
190
- Planter.notify("Applying variables to #{file}", :debug)
190
+ Planter.notify("Applying variables to #{file}", :debug, above_spinner: true)
191
191
  File.open(file, 'w') { |f| f.puts new_content }
192
192
  end
193
193
  end
194
194
 
195
195
  true
196
196
  rescue StandardError => e
197
- Planter.notify("#{e}\n#{e.backtrace}", :debug)
197
+ Planter.notify("#{e}\n#{e.backtrace}", :debug, above_spinner: true)
198
198
  'Error updating files/directories'
199
199
  end
200
200
 
@@ -215,7 +215,7 @@ module Planter
215
215
 
216
216
  true
217
217
  rescue StandardError => e
218
- Planter.notify("#{e}\n#{e.backtrace}", :debug)
218
+ Planter.notify("#{e}\n#{e.backtrace}", :debug, above_spinner: true)
219
219
  'Error initializing git'
220
220
  end
221
221
  end
@@ -54,10 +54,10 @@ module Planter
54
54
  else
55
55
  read_line
56
56
  end
57
- Planter.notify("{dw}#{prompt}: {dy}#{res}{x}", :debug)
57
+ Planter.notify("{dw}#{prompt} => {dy}#{res}{x}", :debug, newline: false)
58
58
  res
59
59
  rescue TTY::Reader::InputInterrupt
60
- raise Errors::InputError('Canceled')
60
+ raise Errors::InputError.new('Canceled')
61
61
  end
62
62
 
63
63
  private
@@ -116,7 +116,7 @@ module Planter
116
116
  default = date_default
117
117
 
118
118
  default = default ? " {bw}[#{default}]" : ''
119
- Planter.notify("{by}#{prompt} (natural language)#{default}")
119
+ Planter.notify("{by}#{prompt} (natural language)#{default}", newline: false)
120
120
  line = @gum ? read_line_gum : read_line_tty
121
121
  return default unless line
122
122
 
@@ -135,7 +135,7 @@ module Planter
135
135
  def read_line(prompt: nil)
136
136
  prompt ||= @prompt
137
137
  default = @default ? " {bw}[#{@default}]" : ''
138
- Planter.notify("{by}#{prompt}#{default}")
138
+ Planter.notify("{by}#{prompt}#{default}", newline: false)
139
139
 
140
140
  res = @gum ? read_line_gum : read_line_tty
141
141
 
@@ -156,7 +156,7 @@ module Planter
156
156
  def read_lines(prompt: nil)
157
157
  prompt ||= @prompt
158
158
  save = @gum ? 'Ctrl-J for newline, Enter' : 'Ctrl-D'
159
- Planter.notify("{by}#{prompt} {xc}({bw}#{save}{xc} to save)'")
159
+ Planter.notify("{by}#{prompt} {xc}({bw}#{save}{xc} to save)'", newline: false)
160
160
  res = @gum ? read_multiline_gum(prompt) : read_mutliline_tty
161
161
 
162
162
  return @default unless res
@@ -15,6 +15,28 @@ module Planter
15
15
  snake_case.to_sym
16
16
  end
17
17
 
18
+ #
19
+ # Convert {a,b,c} to (?:a|b|c)
20
+ #
21
+ # @return [String] Converted string
22
+ #
23
+ def glob_to_rx
24
+ gsub(/\\?\{(.*?)\\?\}/) do
25
+ m = Regexp.last_match
26
+ "(?:#{m[1].split(/,/).map { |c| Regexp.escape(c) }.join('|')})"
27
+ end
28
+ end
29
+
30
+ #
31
+ # Convert a string to a regular expression by escaping special
32
+ # characters and converting wildcards (*,?) to regex wildcards
33
+ #
34
+ # @return [String] String with wildcards converted (not Regexp)
35
+ #
36
+ def to_rx
37
+ gsub(/([.()])/, '\\\\\1').gsub(/\?/, '.').gsub(/\*/, '.*?').glob_to_rx
38
+ end
39
+
18
40
  ##
19
41
  ## Convert a slug into a class name
20
42
  ##
data/lib/planter/tag.rb CHANGED
@@ -4,6 +4,8 @@ module Planter
4
4
  module Tag
5
5
  class << self
6
6
  def set(target, tags)
7
+ return false unless TTY::Which.exist?('xattr')
8
+
7
9
  tags = [tags] unless tags.is_a?(Array)
8
10
 
9
11
  set_tags(target, tags)
@@ -15,15 +17,28 @@ module Planter
15
17
  # @param dir [String] The directory to tag.
16
18
  # @param tags [Array<String>] The tags to add.
17
19
  def add(target, tags)
20
+ return false unless TTY::Which.exist?('xattr')
21
+
18
22
  tags = [tags] unless tags.is_a?(Array)
19
23
  existing_tags = get(target)
20
24
  tags.concat(existing_tags).uniq!
21
25
 
22
26
  set_tags(target, tags)
23
- $? == 0
27
+
28
+ res = $? == 0
29
+
30
+ if res
31
+ Planter.notify("[Added tags] to #{target}", :debug, above_spinner: true)
32
+ else
33
+ Planter.notify("Failed to add tags to #{target}", :error)
34
+ end
35
+
36
+ res
24
37
  end
25
38
 
26
39
  def get(target)
40
+ return false unless TTY::Which.exist?('xattr')
41
+
27
42
  res = `xattr -p com.apple.metadata:_kMDItemUserTags "#{target}" 2>/dev/null`.clean_encode
28
43
  return [] if res =~ /no such xattr/ || res.empty?
29
44
 
@@ -35,19 +50,41 @@ module Planter
35
50
  end
36
51
 
37
52
  def copy(source, target)
53
+ return false unless TTY::Which.exist?('xattr')
54
+
38
55
  tags = `xattr -px com.apple.metadata:_kMDItemUserTags "#{source}" 2>/dev/null`
39
56
  `xattr -wx com.apple.metadata:_kMDItemUserTags "#{tags}" "#{target}"`
40
- $? == 0
57
+ res = $? == 0
58
+
59
+ if res
60
+ Planter.notify("[Copied tags] from #{source} to #{target}", :debug, above_spinner: true)
61
+ else
62
+ Planter.notify("Failed to copy tags from #{source} to #{target}", :error)
63
+ end
64
+
65
+ res
41
66
  end
42
67
 
43
68
  private
44
69
 
45
70
  def set_tags(target, tags)
71
+ return false unless TTY::Which.exist?('xattr')
72
+
46
73
  tags.map! { |tag| "<string>#{tag}</string>" }
47
74
  `xattr -w com.apple.metadata:_kMDItemUserTags '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
48
75
  <plist version="1.0">
49
76
  <array>#{tags.join}</array>
50
77
  </plist>' "#{target}"`
78
+
79
+ res = $? == 0
80
+
81
+ if res
82
+ Planter.notify("[Set tags] on #{target}", :debug, above_spinner: true)
83
+ else
84
+ Planter.notify("Failed to set tags on #{target}", :error)
85
+ end
86
+
87
+ res
51
88
  end
52
89
  end
53
90
  end
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Planter
5
5
  # Current Planter version.
6
- VERSION = '3.0.1'
6
+ VERSION = '3.0.2'
7
7
  end
data/lib/planter.rb CHANGED
@@ -11,9 +11,10 @@ require 'plist'
11
11
  require 'chronic'
12
12
  require 'tty-reader'
13
13
  require 'tty-screen'
14
- require 'tty-spinner'
14
+ # require 'tty-spinner'
15
15
  require 'tty-which'
16
16
 
17
+ require_relative 'tty-spinner/lib/tty-spinner'
17
18
  require_relative 'planter/version'
18
19
  require_relative 'planter/hash'
19
20
  require_relative 'planter/array'
@@ -72,20 +73,28 @@ module Planter
72
73
  ## @param string [String] The message string
73
74
  ## @param notification_type [Symbol] The notification type (:debug, :error, :warn, :info)
74
75
  ## @param exit_code [Integer] If provided, exit with code after delivering message
76
+ ## @param newline [Boolean] If true, add a newline to the message
77
+ ## @param above_spinner [Boolean] If true, print above the spinner
75
78
  ##
76
- def notify(string, notification_type = :info, exit_code: nil)
77
- case notification_type
78
- when :debug
79
- return false unless @debug
80
-
81
- warn "\n{dw}#{string}{x}".x
82
- when :error
83
- warn "{br}#{string}{x}".x
84
- when :warn
85
- warn "{by}#{string}{x}".x
86
- else
87
- warn "{bw}#{string}{x}".x
88
- end
79
+ ## @return [Boolean] true if message was printed
80
+ def notify(string, notification_type = :info, newline: true, above_spinner: false, exit_code: nil)
81
+ color = case notification_type
82
+ when :debug
83
+ return false unless @debug
84
+
85
+ '{dw}'
86
+ when :error
87
+ '{br}'
88
+
89
+ when :warn
90
+ '{by}'
91
+ else
92
+ '{bw}'
93
+ end
94
+ out = "#{color}#{string}{x}"
95
+ out.gsub!(/\[(.*?)\]/, "{by}\\1{x}#{color}")
96
+ out = "\n#{out}" if newline
97
+ above_spinner ? spinner.log(out.x) : warn(out.x)
89
98
 
90
99
  Process.exit exit_code unless exit_code.nil?
91
100
 
@@ -197,13 +206,17 @@ module Planter
197
206
  key: 'var_key',
198
207
  prompt: 'CLI Prompt',
199
208
  type: '[string, float, integer, number, date]',
200
- value: '(optional, for date type can be today, time, now, etc., empty to prompt)',
209
+ value: '(optional, force value, can include variables. Empty to prompt. For date type: today, now, etc.)',
201
210
  default: '(optional default value, leave empty or remove key for no default)',
202
211
  min: '(optional, for number type set a minimum value)',
203
212
  max: '(optional, for number type set a maximum value)'
204
213
  ],
205
214
  git_init: false,
206
- files: { '*.tmp' => 'ignore' }
215
+ files: {
216
+ '*.tmp' => 'ignore',
217
+ '*.bak' => 'ignore',
218
+ '.DS_Store' => 'ignore'
219
+ }
207
220
  }
208
221
  FileUtils.mkdir_p(base_dir)
209
222
  File.open(config, 'w') { |f| f.puts(YAML.dump(default_config.stringify_keys)) }
@@ -238,7 +251,7 @@ module Planter
238
251
  def process_patterns
239
252
  patterns = {}
240
253
  @config[:files].each do |file, oper|
241
- pattern = Regexp.new(".*?/#{file.to_s.sub(%r{^/}, '').gsub(/\./, '\.').gsub(/\*/, '.*?').gsub(/\?/, '.')}$")
254
+ pattern = Regexp.new(".*?/#{file.to_s.sub(%r{^/}, '').to_rx}$")
242
255
  operator = oper.normalize_operator
243
256
  patterns[pattern] = operator
244
257
  end
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*.rb]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ indent_style = space
8
+ indent_size = 2
9
+ trim_trailing_whitespace = true
@@ -0,0 +1 @@
1
+ github: piotrmurach
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report something not working correctly or as expected
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+ ---
8
+
9
+ ### Describe the problem
10
+
11
+ A brief description of the issue.
12
+
13
+ ### Steps to reproduce the problem
14
+
15
+ ```
16
+ Your code here to reproduce the issue
17
+ ```
18
+
19
+ ### Actual behaviour
20
+
21
+ What happened? This could be a description, log output, error raised etc.
22
+
23
+ ### Expected behaviour
24
+
25
+ What did you expect to happen?
26
+
27
+ ### Describe your environment
28
+
29
+ * OS version:
30
+ * Ruby version:
31
+ * TTY::Spinner version:
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest new functionality
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+ ---
8
+
9
+ ### Describe the problem
10
+
11
+ A brief description of the problem you're trying to solve.
12
+
13
+ ### How would the new feature work?
14
+
15
+ A short explanation of the new feature.
16
+
17
+ ```
18
+ Example code that shows possible usage
19
+ ```
20
+
21
+ ### Drawbacks
22
+
23
+ Can you see any potential drawbacks?
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: TTY Community Discussions
4
+ url: https://github.com/piotrmurach/tty/discussions
5
+ about: Suggest ideas, ask and answer questions
@@ -0,0 +1,19 @@
1
+ ### Describe the change
2
+ What does this Pull Request do?
3
+
4
+ ### Why are we doing this?
5
+ Any related context as to why is this is a desirable change.
6
+
7
+ ### Benefits
8
+ How will the library improve?
9
+
10
+ ### Drawbacks
11
+ Possible drawbacks applying this change.
12
+
13
+ ### Requirements
14
+ <!--- Put an X between brackets on each line if you have done the item: -->
15
+ - [ ] Tests written & passing locally?
16
+ - [ ] Code style checked?
17
+ - [ ] Rebased with `master` branch?
18
+ - [ ] Documentation updated?
19
+ - [ ] Changelog updated?
@@ -0,0 +1,59 @@
1
+ ---
2
+ name: CI
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths-ignore:
8
+ - "bin/**"
9
+ - "examples/**"
10
+ - "*.md"
11
+ pull_request:
12
+ branches:
13
+ - master
14
+ paths-ignore:
15
+ - "bin/**"
16
+ - "examples/**"
17
+ - "*.md"
18
+ jobs:
19
+ tests:
20
+ name: Ruby ${{ matrix.ruby }}
21
+ runs-on: ${{ matrix.os || 'ubuntu-latest' }}
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ ruby:
26
+ - "2.0"
27
+ - "2.1"
28
+ - "2.3"
29
+ - "2.4"
30
+ - "2.5"
31
+ - "2.6"
32
+ - "3.0"
33
+ - "3.1"
34
+ - "3.2"
35
+ - "3.3"
36
+ - ruby-head
37
+ - jruby-9.2
38
+ - jruby-9.3
39
+ - jruby-9.4
40
+ - jruby-head
41
+ - truffleruby-head
42
+ include:
43
+ - ruby: "2.2"
44
+ os: ubuntu-20.04
45
+ - ruby: "2.7"
46
+ coverage: true
47
+ env:
48
+ COVERAGE: ${{ matrix.coverage }}
49
+ COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
50
+ continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+ - name: Set up Ruby
54
+ uses: ruby/setup-ruby@v1
55
+ with:
56
+ ruby-version: ${{ matrix.ruby }}
57
+ bundler-cache: true
58
+ - name: Run tests
59
+ run: bundle exec rake ci
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper