pagecord-cli 0.2.0 → 0.2.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: 128d888cf41e5516fb1266253ff9bd277ac4975aabe4d703d55377b487742a9b
4
- data.tar.gz: f1eb62f81e6382bf02babcac836c3ea7f84e855235697950c58e91a3437b4bdb
3
+ metadata.gz: 99eebd4d84788c1c5176bca0d7b1f036bb54ec2acb9e5f6a9f9fef7b63fc5d1d
4
+ data.tar.gz: 78d6e0b1623c066f1b9f992cf87e7e80c997ef7abfa2d2f4e6893ba6e34c0f8f
5
5
  SHA512:
6
- metadata.gz: f392720b150de97d42b8e5d74bf231575e4c90a644653d3d1fb1748c09e1c5896a355be6afc51dbe001c6b95558729728d7387d9b6f66501a24b75b734cdc1f6
7
- data.tar.gz: 2c0b4fc00acfb25fbfdf5ef16f7c20a31f7dfb22c1a4886967561558555279fcf2b553706eb30df0cdac378b08fa8d355f9339639a87cb4491f81330a934e0bc
6
+ metadata.gz: 27842bcc27c07553c69ee4664aad327ab1d1f6155b3eaccc64d66fbcc699d73d543ae09bf2b406f568e6fca1eab83e0976d8f0ed08f62bd30ec63f57e5836796
7
+ data.tar.gz: 245f7e50410b5b93daca45d14ead9268f447cd9bada1bf580db1c73d3c5ec5d39207f7dacbf09fb21c98cc2debfba5d0b97f39b8e3b931b2d183dee9ead935cd
data/README.md CHANGED
@@ -22,7 +22,7 @@ The name should be your Pagecord subdomain. The API key is stored in
22
22
  For local testing there is an undocumented `--base-url` option:
23
23
 
24
24
  ```bash
25
- pagecord login myblog --base-url http://localhost:3000
25
+ pagecord login myblog --base-url http://api.localhost:3000
26
26
  ```
27
27
 
28
28
  ## Publishing
@@ -42,13 +42,6 @@ pagecord draft notes/idea.md
42
42
  The first publish creates a post and writes Pagecord metadata back into the
43
43
  file. Later publishes update the same post.
44
44
 
45
- If you have one blog configured, `publish`, `draft`, and `logout` can omit the
46
- subdomain. If you have more than one, pass the subdomain as the final argument:
47
-
48
- ```bash
49
- pagecord publish hello.md myblog
50
- ```
51
-
52
45
  See configured blogs:
53
46
 
54
47
  ```bash
@@ -63,16 +56,26 @@ pagecord logout myblog
63
56
 
64
57
  ## Choosing a blog
65
58
 
66
- With several blogs configured, pick a default once:
59
+ With one blog configured, every command uses it. With several, set a default
60
+ once:
67
61
 
68
62
  ```bash
69
63
  pagecord blog use myblog
70
64
  ```
71
65
 
72
- Every command works out which blog to use in this order: the subdomain passed
73
- as a positional argument, then `--blog myblog`, then the `PAGECORD_BLOG`
74
- environment variable, then the default set by `pagecord blog use`, and finally
75
- the only configured blog if there is just one.
66
+ or name the blog on the command line:
67
+
68
+ ```bash
69
+ pagecord appearance show --blog myblog
70
+ ```
71
+
72
+ `--blog` wins over the `PAGECORD_BLOG` environment variable, which wins over
73
+ the default. `publish`, `draft` and `logout` also take the subdomain as a
74
+ trailing argument, which wins over all three:
75
+
76
+ ```bash
77
+ pagecord publish hello.md myblog
78
+ ```
76
79
 
77
80
  ## Appearance
78
81
 
@@ -88,17 +91,19 @@ Fields: `--theme`, `--font`, `--width`, `--layout`, the six
88
91
 
89
92
  ```bash
90
93
  pagecord custom-code show --css > blog.css
91
- pagecord custom-code update --css @blog.css
94
+ pagecord custom-code update --css blog.css
92
95
  ```
93
96
 
94
- Fields: `--css`, `--footer-html`, `--head-html`, `--body-html`, and
95
- `--enabled true|false`. A value can be given literally, as `@path` to read a
96
- file, or as `@-` to read standard input:
97
+ `--css`, `--footer-html`, `--head-html` and `--body-html` each take the path to
98
+ a file holding that content, so you can keep all of it under version control:
97
99
 
98
100
  ```bash
99
- cat blog.css | pagecord custom-code update --css @-
101
+ pagecord custom-code update --css blog.css --footer-html footer.html
100
102
  ```
101
103
 
104
+ There is also `--enabled true|false` to switch your head and body code off
105
+ without deleting it.
106
+
102
107
  `custom-code show` prints JSON, or the raw field when you name one, so
103
108
  redirecting it to a file round-trips.
104
109
 
@@ -184,7 +184,7 @@ module PagecordCLI
184
184
  params = {}
185
185
  parser do |opts|
186
186
  CUSTOM_CODE_FIELDS.each do |flag, name|
187
- opts.on("--#{flag} VALUE") { |value| params[name] = read_value(value) }
187
+ opts.on("--#{flag} PATH") { |path| params[name] = read_file(flag, path) }
188
188
  end
189
189
  opts.on("--enabled BOOL", TrueClass) { |value| params["custom_code_enabled"] = value }
190
190
  end.parse!(argv)
@@ -247,12 +247,12 @@ module PagecordCLI
247
247
  end
248
248
 
249
249
  def resolve_blog(name = nil)
250
- raise Error, "No blogs are configured. Run pagecord login SUBDOMAIN first." if config.blogs.empty?
250
+ raise Error, "No blogs are configured. Run `pagecord login SUBDOMAIN` first." if config.blogs.empty?
251
251
 
252
252
  subdomain = name || options[:blog] || ENV["PAGECORD_BLOG"] || config.default_blog ||
253
253
  (config.blogs.keys.first if config.blogs.size == 1)
254
254
 
255
- raise Error, "Please specify a subdomain" unless subdomain
255
+ raise Error, "Several blogs are configured. Pass `--blog SUBDOMAIN`, or run `pagecord blog use SUBDOMAIN` to set a default." unless subdomain
256
256
  raise Error, "Unknown blog: #{subdomain}" unless config.blog(subdomain)
257
257
 
258
258
  subdomain
@@ -266,14 +266,10 @@ module PagecordCLI
266
266
  )
267
267
  end
268
268
 
269
- def read_value(value)
270
- case value
271
- when "@-" then input.read
272
- when /\A@/ then File.read(value[1..])
273
- else value
274
- end
269
+ def read_file(flag, path)
270
+ File.read(path)
275
271
  rescue SystemCallError
276
- raise Error, "Could not read #{value[1..]}"
272
+ raise Error, path.match?(/[{<]/) ? "--#{flag} takes a file path, not the content itself" : "Could not read #{path}"
277
273
  end
278
274
 
279
275
  def say(message)
@@ -319,9 +315,9 @@ module PagecordCLI
319
315
  pagecord draft FILE [SUBDOMAIN] [options]
320
316
 
321
317
  Global options:
322
- --blog SUBDOMAIN
323
- --json
324
- --quiet
318
+ --blog SUBDOMAIN which blog to act on
319
+ --json machine-readable output
320
+ --quiet suppress confirmation messages
325
321
 
326
322
  Publish options:
327
323
  --title TITLE
@@ -339,10 +335,8 @@ module PagecordCLI
339
335
  --show-branding true|false
340
336
 
341
337
  Custom code options:
342
- --css, --footer-html, --head-html, --body-html
338
+ --css, --footer-html, --head-html, --body-html (each takes a file path)
343
339
  --enabled true|false
344
-
345
- Custom code values can be a literal, @path to read a file, or @- to read stdin.
346
340
  HELP
347
341
  0
348
342
  end
@@ -80,7 +80,15 @@ module PagecordCLI
80
80
 
81
81
  def request(http_request)
82
82
  http_request["Authorization"] ||= "Bearer #{api_key}"
83
- response = Net::HTTP.start(http_request.uri.hostname, http_request.uri.port, use_ssl: http_request.uri.scheme == "https") do |http|
83
+ uri = http_request.uri
84
+ address = uri.hostname
85
+ if address.end_with?(".localhost")
86
+ # *.localhost is loopback by definition (RFC 6761); macOS does not resolve it
87
+ http_request["Host"] = "#{uri.host}:#{uri.port}"
88
+ address = "127.0.0.1"
89
+ end
90
+
91
+ response = Net::HTTP.start(address, uri.port, use_ssl: uri.scheme == "https") do |http|
84
92
  http.open_timeout = OPEN_TIMEOUT
85
93
  http.read_timeout = READ_TIMEOUT
86
94
  http.write_timeout = WRITE_TIMEOUT if http.respond_to?(:write_timeout=)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PagecordCLI
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagecord-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olly Headey