bump-cli 0.3.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74840db0ec9bb3819ed5f08bcb3447e837ba8ad788a33c9027752ab18ab37d10
4
- data.tar.gz: 3ef9d162cd65411192160578c32a106888e8e6b9baab455af612aec8d47fe4fd
3
+ metadata.gz: f05f855eadd927f38eaa826e35ca2261414d3e46b004a1f0ebea38cf3687def8
4
+ data.tar.gz: 68b1c1580133034e65b7e501caf218ebbeb4f496c9bb9acc9c2bb5276d0945fa
5
5
  SHA512:
6
- metadata.gz: 417927f5210e5385b6251d869c005f2de5eb7f729e05ce7e346173c3b3ffbcf56f4dd69347876e919892f858a96808b14c38129807f5ccf5fcac851b098077cf
7
- data.tar.gz: d07a810f70501e296dae4e5a7facceae03b9c73b6da92b1c0bac811ae4ca1ee04ffccf7e966ba55e7eafb0d72bc55e35cea104ec66161142aabf63af47b071e0
6
+ metadata.gz: b83e980a9565c4b0ccb28d4853ec70da95e35c3579df9efc251555c370abe82d1568d1005b5e43a505a32fbcad8569181f5c2dca6341af07832663e15025ca16
7
+ data.tar.gz: d6bff352f2a5611cfd293ee9eb142277e9931f0e675f9769ae2f57c0ca534d5d8dca412737529f2126a5624660af1ef7b49b3241c6fa48a604478c5138e192f0
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .byebug_history
2
+ .ruby-version
2
3
  /.bundle/
3
4
  /.yardoc
4
5
  /Gemfile.lock
data/README.md CHANGED
@@ -20,27 +20,40 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- By default, `bump-cli` considers files as `yaml` ones. If you work with JSON definitions, you need to specify the format for all the commands using `--format json`.
23
+ Bump tries to identify your file specification and format automatically. You can force it by using the `--specification` option. Here are the supported values:
24
24
 
25
- The doc `id` and `token` used below can be found in your documentation settings page on https://bump.sh. Note that you can replace the options by environments variables: `--id` can be replaced by `BUMP_ID`, and `--token` can by replaced by `BUMP_TOKEN`. This is useful to keep your private token secret.
25
+ * `openapi/v2/json`
26
+ * `openapi/v2/yaml`
27
+ * `openapi/v3/json`
28
+ * `openapi/v3/yaml`
29
+ * `asyncapi/v2/json`
30
+ * `asyncapi/v2/yaml`
31
+
32
+ `doc` and `token` options used below can be found in your documentation settings page on https://bump.sh. Note that you can replace the token option by an environment variable, to keep it secret: `--token` can by replaced by `BUMP_TOKEN`.
26
33
 
27
34
  ### Preview
28
35
 
29
36
  You can preview your documentation by calling the `preview` command. A temporary preview will be created, with a unique URL. This preview will be available for 30 minutes. You don't need any credentials to use this command.
30
37
 
31
- $ bundle exec bump preview path/to/your/openapi.yml
38
+ Preview a documentation:
39
+
40
+ $ bundle exec bump preview path/to/your/file.yml
32
41
 
33
42
  ### Validate
34
43
 
35
- Validate your file against the OpenApi specification.
44
+ Validate your file against its specification:
36
45
 
37
- $ bundle exec bump validate path/to/your/openapi.yml --id DOC_ID --token DOC_TOKEN
46
+ $ bundle exec bump validate path/to/your/file.yml --doc DOC_ID_OR_SLUG --token DOC_TOKEN
38
47
 
39
48
  ### Deploy
40
49
 
41
- Deploy the file as the current version of the documentation.
50
+ Deploy the file as the current version of the documentation:
51
+
52
+ $ bundle exec bump deploy path/to/your/file.yml --doc DOC_ID_OR_SLUG --token DOC_TOKEN
53
+
54
+ Automatically create a documentation inside a hub and deploy it:
42
55
 
43
- $ bundle exec bump deploy path/to/your/openapi.yml --id DOC_ID --token DOC_TOKEN
56
+ $ bundle exec bump deploy path/to/your/file.yml --auto-create --doc DOC_SLUG --hub HUB_ID_OR_SLUG --token HUB_TOKEN
44
57
 
45
58
  ## Development
46
59
 
@@ -26,13 +26,13 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = '>= 2.3'
28
28
 
29
- spec.add_dependency "hanami-cli", '~> 0'
30
- spec.add_dependency "http", '~> 3'
29
+ spec.add_dependency "dry-cli", '~> 0'
30
+ spec.add_dependency "http", '>= 3'
31
31
 
32
- spec.add_development_dependency "bundler", "~> 1.15"
33
- spec.add_development_dependency "byebug", "~> 9"
32
+ spec.add_development_dependency "bundler", ">= 1", "< 3"
33
+ spec.add_development_dependency "byebug", "~> 11"
34
34
  spec.add_development_dependency "climate_control", '~> 0'
35
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rake", "~> 13"
36
36
  spec.add_development_dependency "rspec", "~> 3"
37
37
  spec.add_development_dependency "webmock", "~> 3"
38
38
  end
@@ -1,5 +1,5 @@
1
1
  require "bump/cli/version"
2
- require "hanami/cli"
2
+ require "dry/cli"
3
3
  require "http"
4
4
 
5
5
  module Bump
@@ -9,11 +9,11 @@ module Bump
9
9
  API_URL = ROOT_URL + API_PATH
10
10
 
11
11
  def call(*args)
12
- Hanami::CLI.new(Commands).call(*args)
12
+ Dry::CLI.new(Commands).call(*args)
13
13
  end
14
14
 
15
15
  module Commands
16
- extend Hanami::CLI::Registry
16
+ extend Dry::CLI::Registry
17
17
  end
18
18
  end
19
19
  end
@@ -1,10 +1,10 @@
1
1
  require 'open-uri'
2
- require 'byebug'
2
+ require 'bump/cli/tools/uuid'
3
3
 
4
4
  module Bump
5
5
  class CLI
6
6
  module Commands
7
- class Base < Hanami::CLI::Command
7
+ class Base < Dry::CLI::Command
8
8
  USER_AGENT = "bump-cli/#{VERSION}".freeze
9
9
 
10
10
  private
@@ -15,11 +15,60 @@ module Bump
15
15
  .post(url, body: body)
16
16
  end
17
17
 
18
- def body(file, specification)
19
- {
20
- definition: open(file).read,
21
- specification: specification
22
- }
18
+ def body(file, **options)
19
+ deprecation_warning(options)
20
+
21
+ compact(
22
+ {
23
+ definition: open(file).read,
24
+ specification: options[:specification],
25
+ validation: options[:validation],
26
+ auto_create_documentation: options[:'auto-create']
27
+ }.merge(documentation_or_hub(options))
28
+ )
29
+ end
30
+
31
+ def deprecation_warning(options)
32
+ if present?(options[:id])
33
+ puts "[DEPRECATION WARNING] --id option is deprecated. Please use --doc instead."
34
+ end
35
+ end
36
+
37
+ def present?(string)
38
+ !string.nil? && string != ''
39
+ end
40
+
41
+ def compact(hash)
42
+ hash.delete_if { |key, value| value.nil? }
43
+ end
44
+
45
+ def documentation_or_hub(options)
46
+ result = {}
47
+
48
+ result[:documentation_id] = options[:id]
49
+ result[:documentation_id] = options[:doc] if documentation_uuid?(options)
50
+ result[:documentation_slug] = options[:doc] if documentation_slug?(options)
51
+ result[:documentation_name] = options[:'doc-name']
52
+ result[:hub_id] = options[:hub] if hub_uuid?(options)
53
+ result[:hub_slug] = options[:hub] if hub_slug?(options)
54
+
55
+ compact(result)
56
+ end
57
+
58
+ def documentation_uuid?(options)
59
+ Bump::CLI::Tools::UUID.valid?(options[:doc])
60
+ end
61
+
62
+ def documentation_slug?(options)
63
+ !options[:doc].nil? && !documentation_uuid?(options)
64
+ end
65
+
66
+ def hub_uuid?(options)
67
+ Bump::CLI::Tools::UUID.valid?(options[:hub])
68
+ end
69
+
70
+ def hub_slug?(options)
71
+ !options[:hub].nil? && !hub_uuid?(options)
23
72
  end
24
73
 
25
74
  def with_errors_rescued
@@ -5,17 +5,22 @@ module Bump
5
5
  module Commands
6
6
  class Deploy < Base
7
7
  desc "Create a new version"
8
- argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
9
- option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
10
- option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
8
+ argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
9
+ option :id, default: ENV.fetch("BUMP_ID", ""), desc: "[DEPRECATED] Documentation id. Use `documentation` option instead"
10
+ option :doc, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation id or slug"
11
+ option :'doc-name', desc: "Documentation name. Used with --auto-create flag."
12
+ option :hub, default: ENV.fetch("BUMP_HUB_ID", ""), desc: "Hub id or slug"
13
+ option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation or Hub token"
11
14
  option :specification, desc: "Specification of the definition"
15
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
16
+ option :'auto-create', type: :boolean, default: false, desc: 'Automatically create the documentation if needed (only available with a hub and when specifying a slug for documentation)'
12
17
 
13
- def call(file:, id:, token:, specification: nil)
18
+ def call(file:, **options)
14
19
  with_errors_rescued do
15
20
  response = post(
16
- url: API_URL + "/docs/#{id}/versions",
17
- body: body(file, specification).to_json,
18
- token: token
21
+ url: API_URL + "/versions",
22
+ body: body(file, options).to_json,
23
+ token: options[:token]
19
24
  )
20
25
 
21
26
  if response.code == 201
@@ -3,14 +3,15 @@ module Bump
3
3
  module Commands
4
4
  class Preview < Base
5
5
  desc "Create a documentation preview for the given file"
6
- argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
6
+ argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
7
7
  option :specification, desc: "Specification of the definition"
8
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
8
9
 
9
- def call(file:, specification: nil)
10
+ def call(file:, **options)
10
11
  with_errors_rescued do
11
12
  response = post(
12
13
  url: API_URL + "/previews",
13
- body: body(file, specification).to_json
14
+ body: body(file, options).to_json
14
15
  )
15
16
 
16
17
  if response.code == 201
@@ -5,17 +5,22 @@ module Bump
5
5
  module Commands
6
6
  class Validate < Base
7
7
  desc "Validate a given file against its schema definition"
8
- argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
9
- option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
10
- option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
8
+ argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
9
+ option :id, default: ENV.fetch("BUMP_ID", ""), desc: "[DEPRECATED] Documentation id. Use `documentation` option instead"
10
+ option :doc, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id or slug"
11
+ option :'doc-name', desc: "Documentation name. Used with --auto-create flag."
12
+ option :hub, desc: "Hub id or slug"
13
+ option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation or Hub token"
11
14
  option :specification, desc: "Specification of the definition"
15
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
16
+ option :'auto-create', type: :boolean, default: false, desc: 'Automatically create the documentation if needed (only available with a hub and when specifying a slug for documentation)'
12
17
 
13
- def call(file:, id:, token:, specification: nil)
18
+ def call(file:, **options)
14
19
  with_errors_rescued do
15
20
  response = post(
16
- url: API_URL + "/docs/#{id}/validations",
17
- body: body(file, specification).to_json,
18
- token: token
21
+ url: API_URL + "/validations",
22
+ body: body(file, options).to_json,
23
+ token: options[:token]
19
24
  )
20
25
 
21
26
  if response.code == 200
@@ -0,0 +1,13 @@
1
+ module Bump
2
+ class CLI
3
+ module Tools
4
+ class UUID
5
+ REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
6
+
7
+ def self.valid?(string)
8
+ string.to_s =~ REGEXP
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Bump
2
2
  class CLI
3
- VERSION = "0.3.1"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehdi Lahmam
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-01-08 00:00:00.000000000 Z
12
+ date: 2020-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: hanami-cli
15
+ name: dry-cli
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
@@ -29,44 +29,50 @@ dependencies:
29
29
  name: http
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '3'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '3'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '1'
49
+ - - "<"
47
50
  - !ruby/object:Gem::Version
48
- version: '1.15'
51
+ version: '3'
49
52
  type: :development
50
53
  prerelease: false
51
54
  version_requirements: !ruby/object:Gem::Requirement
52
55
  requirements:
53
- - - "~>"
56
+ - - ">="
54
57
  - !ruby/object:Gem::Version
55
- version: '1.15'
58
+ version: '1'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: byebug
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
66
  - - "~>"
61
67
  - !ruby/object:Gem::Version
62
- version: '9'
68
+ version: '11'
63
69
  type: :development
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - "~>"
68
74
  - !ruby/object:Gem::Version
69
- version: '9'
75
+ version: '11'
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: climate_control
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -87,14 +93,14 @@ dependencies:
87
93
  requirements:
88
94
  - - "~>"
89
95
  - !ruby/object:Gem::Version
90
- version: '10.0'
96
+ version: '13'
91
97
  type: :development
92
98
  prerelease: false
93
99
  version_requirements: !ruby/object:Gem::Requirement
94
100
  requirements:
95
101
  - - "~>"
96
102
  - !ruby/object:Gem::Version
97
- version: '10.0'
103
+ version: '13'
98
104
  - !ruby/object:Gem::Dependency
99
105
  name: rspec
100
106
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +155,7 @@ files:
149
155
  - lib/bump/cli/commands/deploy.rb
150
156
  - lib/bump/cli/commands/preview.rb
151
157
  - lib/bump/cli/commands/validate.rb
158
+ - lib/bump/cli/tools/uuid.rb
152
159
  - lib/bump/cli/version.rb
153
160
  homepage: https://bump.sh
154
161
  licenses: