faraday-cli 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: e5ef5d377a91ad8e8eabdda498fcad557a29db2e
4
- data.tar.gz: 9c35a33ccb6620728fd954a277ec5ee5d7eb7ff8
3
+ metadata.gz: 05529b7985588b2a66295f2a98ef00c1d73715e0
4
+ data.tar.gz: 830ed39a7103a5b1c15c706a4e35213946f99f33
5
5
  SHA512:
6
- metadata.gz: e6fa22cfa76b24c399d4d23a475c261645b561829e42425f42e86c32e915952be0e857dfaef085307789472e67fe46bec4457d284fbcbd6149d264807aa6f86f
7
- data.tar.gz: c51b1ec867372bd33d75f993f6b00d18e4b1c13e13c99bc8aed6cf4f4563f88aa2467ec3a479d2995606a5ef380aab8b4aa2e9a48d132bdf4653ddad74ecb872
6
+ metadata.gz: 0f36c52ae2b8d68eda145fab01e46d5bef2395e403daafe8cc9c520b9a0c56366ab42bba0ea5d67f538d4a671d80b8bf7c6889930dbb92ff8b848c826a271c7b
7
+ data.tar.gz: e8197d7a109a9865e1766d7520d800af4322efda5baffffb325e999ed65c5005355b9a22ffae64d43900c95248e52fcdc14ba987ce95a7df0dfd5959a0bab546
data/README.md CHANGED
@@ -36,8 +36,10 @@ Usage: faraday-cli [options] <url>
36
36
  -o, --output FILE_PATH Write to FILE instead of stdout
37
37
  -s, --silent Silent mode (don't output anything)
38
38
  -c, --config FILE_PATH File path to the .faraday.rb if you want use other than default
39
-
40
- faraday-cli http://www.google.com -q "q=hello world"
39
+ -M, --middlewares Show current middleware stack
40
+
41
+ faraday-cli http://www.google.com -q q=foo
42
+ faraday-cli http://example.org -d "payload string"
41
43
  ```
42
44
 
43
45
  ### Middleware use
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/bin/faraday-cli CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # if ENV['DEVELOPER_ENV'] == 'true'
3
- # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- # end
2
+ if ENV['FARADAY_CLI_DEVELOPER_ENV'] == 'true'
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ end
5
5
 
6
6
  require 'optparse'
7
7
  require 'faraday/cli'
@@ -64,11 +64,15 @@ OptionParser.new do |o|
64
64
  # CLI_OPTIONS[:proxy]= {host: host, port: port}
65
65
  # end
66
66
 
67
+ o.on('-v','--verbose','Make the operation more talkative') do
68
+ CLI_OPTIONS[:flags] << :verbose
69
+ end
70
+
67
71
  o.on('-s', '--silent', "Silent mode (don't output anything)") { CLI_OPTIONS[:flags] << :silent }
68
72
 
69
73
  CLI_OPTIONS[:config_file_paths]= []
70
74
  o.on('-c', '--config FILE_PATH', 'File path to the .faraday.rb if you want use other than default') do |file_path|
71
- CLI_OPTIONS[:config_file_paths] << File.realpath(file_path)
75
+ CLI_OPTIONS[:config_file_paths] << File.absolute_path(file_path)
72
76
  end
73
77
 
74
78
  o.on('-M','--middlewares','Show current middleware stack') do
@@ -86,7 +90,7 @@ connection = Faraday.new do |builder|
86
90
  Faraday::CLI::MiddlewareFetcher.extend!(builder, *CLI_OPTIONS[:config_file_paths])
87
91
 
88
92
  builder.request(:multipart) if CLI_OPTIONS[:flags].include?(:multipart)
89
- builder.response :logger unless CLI_OPTIONS[:flags].include?(:silent)
93
+ builder.response :logger if !CLI_OPTIONS[:flags].include?(:silent) && CLI_OPTIONS[:flags].include?(:verbose)
90
94
 
91
95
  builder.adapter(:net_http)
92
96
 
@@ -115,5 +119,5 @@ response = connection.public_send(CLI_OPTIONS[:http_method].downcase) do |reques
115
119
  end
116
120
 
117
121
 
118
- $stdout.puts Faraday::CLI::ResponseFormatter.format(response) unless CLI_OPTIONS[:flags].include?(:silent)
122
+ $stdout.puts Faraday::CLI::ResponseFormatter.format(response,*CLI_OPTIONS[:flags]) unless CLI_OPTIONS[:flags].include?(:silent)
119
123
  exit(1) unless (200..299).include?(response.status)
data/faraday-cli.gemspec CHANGED
@@ -1,11 +1,9 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'faraday/cli'
2
+ VERSION = File.read(File.join(File.dirname(__FILE__),'VERSION')).strip
5
3
 
6
4
  Gem::Specification.new do |spec|
7
5
  spec.name = "faraday-cli"
8
- spec.version = Faraday::CLI::VERSION
6
+ spec.version = VERSION
9
7
  spec.authors = ["Adam Luzsi"]
10
8
  spec.email = ["adamluzsi@gmail.com"]
11
9
 
@@ -13,24 +13,44 @@ module Faraday::CLI::MiddlewareFetcher
13
13
 
14
14
  def get_file_paths(config_file_paths)
15
15
  file_name = '{.faraday.rb,.faraday}'
16
+ folder_name = '{.faraday.rb,.faraday,.faraday-cli}'
17
+
16
18
  case
17
19
 
18
20
  when !config_file_paths.empty?
19
- config_file_paths
21
+ config_file_paths.reduce([]) do |file_paths, given_path|
22
+ file_paths.push(*Dir.glob(given_path)); file_paths
23
+ end
20
24
 
21
25
  when !(file_paths = Dir.glob(File.join(Dir.pwd, file_name))).empty?
22
26
  file_paths
23
27
 
28
+ when !(file_paths = folder_content(Dir.pwd, folder_name)).empty?
29
+ file_paths
30
+
24
31
  when !(file_paths = Dir.glob(File.join(PWD.pwd, file_name))).empty?
25
32
  file_paths
26
33
 
34
+ when !(file_paths = folder_content(PWD.pwd, folder_name)).empty?
35
+ file_paths
36
+
27
37
  when !(file_paths = Dir.glob(File.join(ENV['HOME'], file_name))).empty?
28
38
  file_paths
29
39
 
40
+ when !(file_paths = folder_content(ENV['HOME'], folder_name)).empty?
41
+ file_paths
42
+
30
43
  else
31
44
  []
32
45
 
33
46
  end
34
47
  end
35
48
 
49
+
50
+ protected
51
+
52
+ def folder_content(main_path, folder_name)
53
+ Dir.glob(File.join(main_path, folder_name, '*.rb')).select { |path| not File.directory?(path) }
54
+ end
55
+
36
56
  end
@@ -2,9 +2,9 @@ require 'yaml'
2
2
  module Faraday::CLI::ResponseFormatter
3
3
  extend self
4
4
 
5
- def format(faraday_response)
5
+ def format(faraday_response,*flags)
6
6
  formatted_message_parts = []
7
- formatted_message_parts << YAML.dump(response_hash_by(faraday_response))
7
+ formatted_message_parts << YAML.dump(response_hash_by(faraday_response)) if flags.include?(:verbose)
8
8
  formatted_message_parts << faraday_response.body
9
9
 
10
10
  formatted_message_parts.join("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi