gistribute 0.3 → 0.3.1

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: 54d0c1a3f95efadf4af148ba00f9c52f66bc80b4f979d357a7430c5c412e96ab
4
- data.tar.gz: 49fafdc9abd4ba1d994f796cf047c925159ee3d9bf9128386a8e3341fff04194
3
+ metadata.gz: 97e259b2b9206eb05470a31911d121166d9ed55d94ea1eb2b2be860c9befec47
4
+ data.tar.gz: 97e818cbd5638d50782e2a95a910da6ab6c83724a6dcefbe01bd4699c4757f68
5
5
  SHA512:
6
- metadata.gz: 4d01816a4228bf6041d1b6753b77655ce613166e4bdc8772a9d2e8482d1031fde7b3607c9664ccbd855b85d4e84ed82805dec1401f9d7a9c99af75fdd7991e4a
7
- data.tar.gz: 83041e56c9d92034509149eb5a1968cdfea92dba1b15d3d66751b3597d2c602940e078a9eed2af3fd92f191cc9a05d9ad41687be5538180c9180c2bf53bef08e
6
+ metadata.gz: 7f45614e316c434a25cb92bca518faee4e3101ae8beadbc7ce60fbd4b73ac90ff5b5350fec966c078af5c79eb04dae91ee7609c754b443f2fa37b2bb0e4ad18d
7
+ data.tar.gz: f3977be4e4fbd3dbb29fb0b5569afdbea87f3bf9b8bf9e8569fd4dc155bed0410265688499f35fdc355c6a9c88a07a7c28de07f0b05682865e2e71f1e9a7f6c7
data/README.md CHANGED
@@ -32,6 +32,13 @@ use the name of the file (without the path to it) as the default description.
32
32
 
33
33
  ## Usage
34
34
 
35
+ For a detailed description of the available options, try one of the following:
36
+
37
+ ```sh
38
+ gistribute upload -h
39
+ gistribute install -h
40
+ ```
41
+
35
42
  ### Uploads
36
43
 
37
44
  To upload a gistribution, use the `upload` subcommand and pass in as many files
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3
1
+ 0.3.1
data/lib/cli/install.rb CHANGED
@@ -26,6 +26,7 @@ module Gistribute
26
26
  # check to see if it's empty- if not, put newlines on each side so that it
27
27
  # will be padded when displayed in the output.
28
28
  gist_description = gist.description.gsub(/(.{1,79})(\s+|\Z)/, "\\1\n").strip
29
+ .sub(/^\[gistribut(e|ion)\] ?/, "")
29
30
  gist_description = "\n#{gist_description}\n" unless gist_description.empty?
30
31
 
31
32
  # Process files
data/lib/cli/upload.rb CHANGED
@@ -31,7 +31,7 @@ module Gistribute
31
31
  end
32
32
 
33
33
  def process_file(file)
34
- file = File.expand_path(file)
34
+ file = @subcommand_options.relative ? file : File.expand_path(file)
35
35
 
36
36
  if File.directory?(file)
37
37
  # Recursively process every file in the directory
data/lib/cli.rb CHANGED
@@ -62,6 +62,7 @@ module Gistribute
62
62
  opt :description, "description for the Gist", type: :string
63
63
  opt :private, "use a private Gist"
64
64
  opt :yes, "upload files without prompting"
65
+ opt :relative, "use relative file paths"
65
66
  end
66
67
 
67
68
  educate_on_error
@@ -8,14 +8,19 @@ MULTI_FILENAMES = ["file1", "dir/file2"].freeze
8
8
  SINGLE_FILE_CONTENTS = "Line 1\nLine 2\n"
9
9
 
10
10
  # Test Gists
11
- PUB_SINGLE_FILE_ID = "4346763"
12
- SEC_SINGLE_FILE_ID = "5fa3c6bab88036e95d62cadf15128ec3"
13
- NO_TITLE_ID = "5865a130f9cf40acd9f0e85d15e601a7"
14
- NO_PIPE_SPACING_ID = "5677679b0db25054521753e5d59bed3d"
15
- NON_EXISTENT_DIR_ID = "8c86bf9cda921ebe7ad1bf0c46afb108"
16
- MULTI_FILE_ID = "8d4a2a4c8fe0b1427fed39c939857a40"
17
- CWD_ID = "3c7006e629fcc54262ef02a5b2204735"
18
- HOME_ID = "acb6caa80886101a68c5c85e4c100ddb"
11
+
12
+ GIST_IDS = {
13
+ pub_single_file: "4346763",
14
+ sec_single_file: "5fa3c6bab88036e95d62cadf15128ec3",
15
+ no_title: "5865a130f9cf40acd9f0e85d15e601a7",
16
+ no_pipe_spacing: "5677679b0db25054521753e5d59bed3d",
17
+ non_existent_dir: "8c86bf9cda921ebe7ad1bf0c46afb108",
18
+ multi_file: "8d4a2a4c8fe0b1427fed39c939857a40",
19
+ cwd: "3c7006e629fcc54262ef02a5b2204735",
20
+ home: "acb6caa80886101a68c5c85e4c100ddb",
21
+ gist_description: "332d3f90378380a00614a088d9c179c5",
22
+ no_gist_description: "b35c3fcf05af11b7efc1a5dbd11d23be"
23
+ }
19
24
 
20
25
  def test_single_file(id, path)
21
26
  before { run "install", id }
@@ -46,10 +51,10 @@ describe Gistribute::CLI do
46
51
  before { simulate_user_input "y\n" }
47
52
 
48
53
  {
49
- "public single file": PUB_SINGLE_FILE_ID,
50
- "secret single file": SEC_SINGLE_FILE_ID,
51
- "no title": NO_TITLE_ID,
52
- "no || spacing": NO_PIPE_SPACING_ID
54
+ "public single file": GIST_IDS[:pub_single_file],
55
+ "secret single file": GIST_IDS[:sec_single_file],
56
+ "no title": GIST_IDS[:no_title],
57
+ "no || spacing": GIST_IDS[:no_pipe_spacing]
53
58
  }.each do |description, id|
54
59
  context "when run with a #{description} Gist" do
55
60
  test_single_file id, TEMP
@@ -57,7 +62,7 @@ describe Gistribute::CLI do
57
62
  end
58
63
 
59
64
  context "when given a directory that doesn't exist" do
60
- before { run "install", NON_EXISTENT_DIR_ID }
65
+ before { run "install", GIST_IDS[:non_existent_dir] }
61
66
 
62
67
  let(:file_contents) { File.read "#{TEMP}/#{NEW_DIR_FILENAME}" }
63
68
 
@@ -67,7 +72,7 @@ describe Gistribute::CLI do
67
72
  end
68
73
 
69
74
  context "when run with a multi-file Gist" do
70
- before { run "install", MULTI_FILE_ID }
75
+ before { run "install", GIST_IDS[:multi_file] }
71
76
 
72
77
  let(:file1_contents) { File.read "#{TEMP}/#{MULTI_FILENAMES[0]}" }
73
78
  let(:file2_contents) { File.read "#{TEMP}/#{MULTI_FILENAMES[1]}" }
@@ -81,11 +86,11 @@ describe Gistribute::CLI do
81
86
  end
82
87
 
83
88
  context "when given a file for the current working directory" do
84
- test_single_file CWD_ID, Dir.pwd
89
+ test_single_file GIST_IDS[:cwd], Dir.pwd
85
90
  end
86
91
 
87
92
  context "when given a file for the home directory" do
88
- test_single_file HOME_ID, Dir.home
93
+ test_single_file GIST_IDS[:home], Dir.home
89
94
  end
90
95
 
91
96
  context "when given a bad ID (404)" do
@@ -105,12 +110,35 @@ describe Gistribute::CLI do
105
110
  expect($stderr).to have_received(:puts).with("bad")
106
111
  end
107
112
  end
113
+
114
+ context "when given a Gist with only a description" do
115
+ before { run "install", GIST_IDS[:gist_description] }
116
+
117
+ it "prints the description" do
118
+ expect($stdout).to have_received(:write)
119
+ .with(a_string_including("test description"))
120
+ end
121
+
122
+ it "removes the `[gistribution]` from the beginning" do
123
+ expect($stdout).not_to have_received(:write)
124
+ .with(a_string_including("[gistribution]"))
125
+ end
126
+ end
127
+
128
+ context "when given a Gist with only `[gistribution]` in the description" do
129
+ before { run "install", GIST_IDS[:no_gist_description] }
130
+
131
+ it "doesn't print the description" do
132
+ expect($stdout).not_to have_received(:write)
133
+ .with(a_string_including("[gistribution]"))
134
+ end
135
+ end
108
136
  end
109
137
 
110
138
  context "when user inputs nothing at the installation prompt" do
111
139
  before do
112
140
  simulate_user_input "\n"
113
- run "install", PUB_SINGLE_FILE_ID
141
+ run "install", GIST_IDS[:pub_single_file]
114
142
  end
115
143
 
116
144
  it "saves the file" do
@@ -122,7 +150,7 @@ describe Gistribute::CLI do
122
150
  context "when user inputs `#{ch}` at the installation prompt" do
123
151
  before do
124
152
  simulate_user_input "#{ch}\n"
125
- run "install", PUB_SINGLE_FILE_ID
153
+ run "install", GIST_IDS[:pub_single_file]
126
154
  end
127
155
 
128
156
  it "doesn't save the file" do
@@ -147,7 +175,7 @@ describe Gistribute::CLI do
147
175
  context "when the user inputs `y` at the file overwrite prompts" do
148
176
  before do
149
177
  simulate_user_input "y\n", "y\n", "y\n"
150
- run "install", MULTI_FILE_ID
178
+ run "install", GIST_IDS[:multi_file]
151
179
  end
152
180
 
153
181
  it "downloads the files into the correct locations" do
@@ -158,7 +186,7 @@ describe Gistribute::CLI do
158
186
  context "when the user inputs `n` at the file overwrite prompts" do
159
187
  before do
160
188
  simulate_user_input "y\n", "n\n", "n\n"
161
- run "install", MULTI_FILE_ID
189
+ run "install", GIST_IDS[:multi_file]
162
190
  end
163
191
 
164
192
  it "doesn't download the files" do
@@ -169,7 +197,7 @@ describe Gistribute::CLI do
169
197
  context "with the `--force` flag" do
170
198
  before do
171
199
  simulate_user_input "y\n"
172
- run "install", "--force", MULTI_FILE_ID
200
+ run "install", "--force", GIST_IDS[:multi_file]
173
201
  end
174
202
 
175
203
  it "overwrites the files without prompting" do
@@ -181,7 +209,7 @@ describe Gistribute::CLI do
181
209
  end
182
210
 
183
211
  context "when ran with the --yes flag" do
184
- before { run "install", "--yes", PUB_SINGLE_FILE_ID }
212
+ before { run "install", "--yes", GIST_IDS[:pub_single_file] }
185
213
 
186
214
  let(:file_contents) { File.read "#{TEMP}/#{FILENAME}" }
187
215
 
@@ -157,5 +157,44 @@ describe Gistribute::CLI do
157
157
  expect(octokit_client).to have_received(:create_gist)
158
158
  end
159
159
  end
160
+
161
+ context "with the `--relative` flag" do
162
+ context "with a single file" do
163
+ before do
164
+ File.write(FILENAME, SINGLE_FILE_CONTENT)
165
+ simulate_user_input "Test File\n", "y\n"
166
+ run "upload", "--relative", FILENAME
167
+ end
168
+
169
+ after { File.delete FILENAME }
170
+
171
+ it "uploads with a relative file path" do
172
+ expect(octokit_client).to have_received(:create_gist)
173
+ .with(a_hash_including(files: { "Test File || #{FILENAME}" => anything }))
174
+ end
175
+ end
176
+
177
+ context "with a single directory" do
178
+ let(:test_dir) { "test_dir" }
179
+
180
+ before do
181
+ FileUtils.mkdir test_dir
182
+ [1, 2].each { |n| FileUtils.touch "#{test_dir}/file#{n}" }
183
+
184
+ simulate_user_input "File 1\n", "File 2\n", "y\n"
185
+ run "upload", "--relative", test_dir
186
+ end
187
+
188
+ after { FileUtils.rm_rf test_dir }
189
+
190
+ it "uploads with a relative file path" do
191
+ expect(octokit_client).to have_received(:create_gist)
192
+ .with(a_hash_including(files: {
193
+ "File 1 || #{test_dir}|file1" => anything,
194
+ "File 2 || #{test_dir}|file2" => anything
195
+ }))
196
+ end
197
+ end
198
+ end
160
199
  end
161
200
  end
@@ -4,7 +4,9 @@ require "spec_helper"
4
4
 
5
5
  describe Gistribute do
6
6
  describe "::parse_id" do
7
- [PUB_SINGLE_FILE_ID, SEC_SINGLE_FILE_ID].each do |id|
7
+ %i[pub_single_file sec_single_file].each do |gist|
8
+ id = GIST_IDS[gist]
9
+
8
10
  [
9
11
  "https://gist.github.com/username/#{id}",
10
12
  "https://gist.github.com/#{id}",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistribute
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl