This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from apiaryio/abtris/refactor-thor
Refactor thor
- Loading branch information
Showing
23 changed files
with
211 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test: | ||
override: | ||
- bundle exec rake test | ||
- bundle exec rake features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Fetch apiary.apib from API_NAME.apiary.io | ||
|
||
# This is integration testing you have to set APIARY_API_KEY | ||
Scenario: Fetch apiary.apib from API_NAME.apiary.io | ||
|
||
When I run `apiary fetch --api-name apiaryclienttest` | ||
Then the output should contain the content of file "apiary.apib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
FORMAT: 1A | ||
|
||
# Apiary Client Test - DON'T CHANGE DOCUMENT! | ||
|
||
This document is used for testing apiary-client | ||
|
||
# Group Notes | ||
Notes related resources of the **Notes API** | ||
|
||
## Notes Collection [/notes | ||
### List all Notes [GET] | ||
+ Response 200 (application/json) | ||
|
||
[{ | ||
"id": 1, "title": "Jogging in park" | ||
}, { | ||
"id": 2, "title": "Pick-up posters from post-office" | ||
}] | ||
|
||
### Create a Note [POST | ||
|
||
+ Request | ||
|
||
sflmvs;mv;dsm{ "title": "Buy cheese and bread for breakfast." } | ||
|
||
+ Response 201 (application/json) | ||
|
||
{ "id": 3, "title": "Buy cheese and bread for breakfast." } | ||
|
||
## Note [/notes/{id}] | ||
A single Note object with all its details | ||
|
||
+ Parameters | ||
+ id (required, number, `1`) ... Numeric `id` of the Note to perform action with. Has example value. | ||
|
||
### Retrieve a Note [GET] | ||
+ Response 200 (application/json) | ||
|
||
+ Header | ||
|
||
X-My-Header: The Value | ||
|
||
+ Body | ||
|
||
{ "id": 2, "title": "Pick-up posters from post-office" } | ||
|
||
### Remove a Note [DELETE] | ||
+ Response 204 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Show API documentation in specified browser | ||
|
||
# This is integration testing you have to set APIARY_API_KEY | ||
Scenario: Write generated HTML into specified file | ||
|
||
When I run `apiary preview --path apiary.apib --output=test.html` | ||
Then a file named "test.html" should exist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Publish apiary.apib on docs.API_NAME.apiary.io | ||
|
||
# This is integration testing you have to set APIARY_API_KEY | ||
Scenario: Publish apiary.apib on docs.API_NAME.apiary.io | ||
|
||
When I run `apiary publish --path=apiary.apib --api-name 1111apiaryclienttest` | ||
Then the exit status should be 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Then /^the output should contain the content of file "(.*)"$/ do |filename| | ||
expected = nil | ||
in_current_dir do | ||
expected = File.read(filename) | ||
end | ||
|
||
assert_partial_output(expected, all_output) | ||
end | ||
|
||
|
||
Then /^output file "(.*)" should contain the content of file "(.*)"$/ do |input, output| | ||
expected = nil | ||
in_current_dir do | ||
actual = File.read(input) | ||
expected = File.read(output) | ||
end | ||
|
||
assert_partial_output(expected, actual) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'aruba/cucumber' | ||
require 'fileutils' | ||
|
||
Before do | ||
@dirs << "../../features/fixtures" | ||
ENV['PATH'] = "./bin#{File::PATH_SEPARATOR}#{ENV['PATH']}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'aruba/cucumber' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: Version of Apiary client | ||
|
||
Scenario: Print the semantic version of Apiary client | ||
|
||
# Note the output should be a semantic version (semver.org) | ||
# The matching regex was taken from https://github.com/isaacs/node-semver/issues/32#issue-15023919 | ||
|
||
When I run `apiary version` | ||
Then the output should match /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ | ||
And the exit status should be 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,51 @@ | ||
# encoding: utf-8 | ||
require 'optparse' | ||
require "thor" | ||
require "apiary/command/fetch" | ||
require "apiary/command/preview" | ||
require "apiary/command/publish" | ||
|
||
module Apiary | ||
class CLI | ||
class CLI < Thor | ||
|
||
attr_reader :command | ||
desc "fetch", "Fetch apiary.apib from API_NAME.apiary.io" | ||
method_option :api_name, :type => :string, :required => true, :default => '' | ||
|
||
def initialize(args) | ||
options = parse_options!(args) | ||
@command = options.delete(:command) | ||
run(options) | ||
def fetch | ||
cmd = Apiary::Command::Fetch.new options | ||
cmd.execute | ||
end | ||
|
||
def run(options) | ||
Apiary::Command::Runner.run(@command, options) | ||
desc "preview", "Show API documentation in default browser" | ||
method_option :browser, :type => :string, :enum => %w(chrome safari firefox), :banner => "chrome|safari|firefox", :desc => "Show API documentation in specified browser" | ||
method_option :output, :type => :string, :banner => "FILE", :desc => "Write generated HTML into specified file" | ||
method_option :path, :type => :string, :desc => "Specify path to blueprint file", :default => 'apiary.apib' | ||
method_option :api_host, :type => :string, :banner => "HOST", :desc => "Specify apiary host" | ||
method_option :server, :type => :boolean, :desc => "Start standalone web server on port 8080" | ||
method_option :port, :type => :numeric, :banner => "PORT", :desc => "Set port for --server option" | ||
|
||
def preview | ||
cmd = Apiary::Command::Preview.new options | ||
cmd.execute | ||
end | ||
|
||
def parse_options!(args) | ||
options = {} | ||
command = nil | ||
if args.first && !args.first.start_with?("-") | ||
command = args.first | ||
end | ||
|
||
options_parser = OptionParser.new do |opts| | ||
opts.on("--path [PATH]") do |path| | ||
raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command | ||
options[:path] = path | ||
end | ||
|
||
opts.on("--output [PATH]") do |path| | ||
raise OptionParser::InvalidOption unless ["fetch", "preview"].include? command | ||
options[:output] = path | ||
end | ||
|
||
opts.on("--api_host API_HOST") do |api_host| | ||
raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command | ||
options[:api_host] = api_host | ||
end | ||
|
||
opts.on("--api-name API_HOST") do |api_name| | ||
raise OptionParser::InvalidOption unless ["fetch", "publish"].include? command | ||
options[:api_name] = api_name | ||
end | ||
|
||
opts.on("--message COMMIT_MESSAGE") do |commit_message| | ||
raise OptionParser::InvalidOption if command != "publish" | ||
options[:commit_message] = commit_message | ||
end | ||
|
||
opts.on("--browser BROWSER") do |browser| | ||
raise OptionParser::InvalidOption if command != "preview" | ||
options[:browser] = browser | ||
end | ||
desc "publish", "Publish apiary.apib on docs.API_NAME.apiary.io" | ||
method_option :message, :type => :string, :banner => "COMMIT_MESSAGE", :desc => "Publish with custom commit message" | ||
method_option :path, :type => :string, :desc => "Specify path to blueprint file", :default => 'apiary.apib' | ||
method_option :api_host, :type => :string, :banner => "HOST", :desc => "Specify apiary host" | ||
method_option :api_name, :type => :string, :required => true, :default => '' | ||
|
||
opts.on("--server") do | ||
raise OptionParser::InvalidOption if command != "preview" | ||
options[:server] = true | ||
end | ||
|
||
opts.on("--port [PORT]") do |port| | ||
raise OptionParser::InvalidOption unless ["fetch", "preview", "publish"].include? command | ||
options[:port] = port | ||
end | ||
|
||
opts.on('-v', '--version') do | ||
raise OptionParser::InvalidOption if command | ||
command = :version | ||
end | ||
|
||
opts.on( '-h', '--help') do | ||
raise OptionParser::InvalidOption if command | ||
command = :help | ||
end | ||
end | ||
def publish | ||
cmd = Apiary::Command::Publish.new options | ||
cmd.execute | ||
end | ||
|
||
options_parser.parse! | ||
options[:command] = command || :help | ||
options | ||
desc "version", "Show version" | ||
method_option :aliases => "-v" | ||
|
||
rescue OptionParser::InvalidOption => e | ||
puts e | ||
puts Apiary::Command::Help.banner | ||
exit 1 | ||
def version | ||
puts Apiary::VERSION | ||
end | ||
|
||
end | ||
end | ||
|
||
Apiary::CLI.start(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.