forward 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -7
- data/lib/forward.rb +5 -1
- data/lib/forward/cli.rb +7 -7
- data/lib/forward/config.rb +2 -10
- data/lib/forward/version.rb +1 -1
- data/test/cli_test.rb +21 -6
- metadata +2 -2
data/README.md
CHANGED
@@ -1,7 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
# Forward
|
2
|
+
|
3
|
+
The ruby client for [https://forwardhq.com/](https://forwardhq.com/). Forward gives you a sharable URL for localhost websites/webapps.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
> forward <port> [options]
|
8
|
+
> forward <host> [options]
|
9
|
+
> forward <host:port> [options]
|
10
|
+
|
11
|
+
Description:
|
12
|
+
|
13
|
+
Share a server running on localhost:port over the web by tunneling
|
14
|
+
through Forward. A URL is created for each tunnel.
|
15
|
+
|
16
|
+
Simple example:
|
17
|
+
|
18
|
+
# You are developing a Rails site.
|
19
|
+
|
20
|
+
> rails server &
|
21
|
+
> forward 3000
|
22
|
+
Forward created at https://mycompany.fwd.wf
|
23
|
+
|
24
|
+
Assigning a static subdomain prefix:
|
25
|
+
|
26
|
+
> rails server &
|
27
|
+
> forward 3000 myapp
|
28
|
+
Forward created at https://myapp-mycompany.fwd.wf
|
29
|
+
|
30
|
+
Virtual Host example:
|
31
|
+
|
32
|
+
# You are already running something on port 80 that uses
|
33
|
+
# virtual host names.
|
34
|
+
|
35
|
+
> forward mysite.dev
|
36
|
+
Forward created at https://mycompany.fwd.wf
|
data/lib/forward.rb
CHANGED
@@ -39,6 +39,10 @@ module Forward
|
|
39
39
|
ENV['FORWARD_SSH_PORT'] || DEFAULT_SSH_PORT
|
40
40
|
end
|
41
41
|
|
42
|
+
def self.windows?
|
43
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
44
|
+
end
|
45
|
+
|
42
46
|
def self.config=(config)
|
43
47
|
@config = config
|
44
48
|
end
|
@@ -81,7 +85,7 @@ module Forward
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def self.logdev
|
84
|
-
@logdev ||= '/dev/null'
|
88
|
+
@logdev ||= (windows? ? 'NUL:' : '/dev/null')
|
85
89
|
end
|
86
90
|
|
87
91
|
def self.log
|
data/lib/forward/cli.rb
CHANGED
@@ -21,9 +21,9 @@ module Forward
|
|
21
21
|
|
22
22
|
> rails server &
|
23
23
|
> forward 3000
|
24
|
-
Forward created at https://
|
24
|
+
Forward created at https://mycompany.fwd.wf
|
25
25
|
|
26
|
-
Assigning a subdomain prefix:
|
26
|
+
Assigning a static subdomain prefix:
|
27
27
|
|
28
28
|
> rails server &
|
29
29
|
> forward 3000 myapp
|
@@ -35,14 +35,14 @@ module Forward
|
|
35
35
|
# virtual host names.
|
36
36
|
|
37
37
|
> forward mysite.dev
|
38
|
-
Forward created at https://
|
38
|
+
Forward created at https://mycompany.fwd.wf
|
39
39
|
|
40
40
|
BANNER
|
41
41
|
|
42
42
|
# Parse non-published options and remove them from ARGV, then
|
43
43
|
# parse published options and update the options Hash with provided
|
44
44
|
# options and removes switches from ARGV.
|
45
|
-
def self.parse_cli_options
|
45
|
+
def self.parse_cli_options(args)
|
46
46
|
Forward.log.debug("Parsing options")
|
47
47
|
options = {}
|
48
48
|
|
@@ -78,7 +78,7 @@ module Forward
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
@opts.parse!
|
81
|
+
@opts.parse!(args)
|
82
82
|
|
83
83
|
options
|
84
84
|
end
|
@@ -106,7 +106,7 @@ module Forward
|
|
106
106
|
Forward.log.debug("Forwardfile options: `#{options.inspect}'")
|
107
107
|
end
|
108
108
|
|
109
|
-
options.merge!(parse_cli_options)
|
109
|
+
options.merge!(parse_cli_options(args))
|
110
110
|
|
111
111
|
forwarded, prefix = args[0..1]
|
112
112
|
options[:subdomain_prefix] = prefix unless prefix.nil?
|
@@ -230,7 +230,7 @@ module Forward
|
|
230
230
|
# Parses various options and arguments, validates everything to ensure
|
231
231
|
# we're safe to proceed, and finally passes options to the Client.
|
232
232
|
def self.run(args)
|
233
|
-
::HighLine.use_color = false if Forward
|
233
|
+
::HighLine.use_color = false if Forward.windows?
|
234
234
|
if ARGV.include?('--debug')
|
235
235
|
Forward.debug!
|
236
236
|
ARGV.delete('--debug')
|
data/lib/forward/config.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'rbconfig'
|
3
2
|
require 'yaml'
|
4
3
|
|
5
4
|
module Forward
|
@@ -80,19 +79,12 @@ module Forward
|
|
80
79
|
raise ConfigError, 'Unable to write config file'
|
81
80
|
end
|
82
81
|
|
83
|
-
# Shortcut for checking if host os is windows.
|
84
|
-
#
|
85
|
-
# Returns true or false if windows or not.
|
86
|
-
def self.windows?
|
87
|
-
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
88
|
-
end
|
89
|
-
|
90
82
|
# Returns the location of the forward ssh private key
|
91
83
|
# based on the host os.
|
92
84
|
#
|
93
85
|
# Returns the String path.
|
94
86
|
def self.key_path
|
95
|
-
if windows?
|
87
|
+
if Forward.windows?
|
96
88
|
File.join(ENV['HOME'], 'forward', 'key')
|
97
89
|
else
|
98
90
|
File.join(ENV['HOME'], '.ssh', 'forwardhq.com')
|
@@ -104,7 +96,7 @@ module Forward
|
|
104
96
|
#
|
105
97
|
# Returns the String path.
|
106
98
|
def self.config_path
|
107
|
-
if windows?
|
99
|
+
if Forward.windows?
|
108
100
|
File.join(ENV['HOME'], 'forward', 'config')
|
109
101
|
else
|
110
102
|
File.join(ENV['HOME'], '.forward')
|
data/lib/forward/version.rb
CHANGED
data/test/cli_test.rb
CHANGED
@@ -51,24 +51,34 @@ describe Forward::CLI do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'parses a Forwardfile' do
|
54
|
-
|
55
|
-
File.open('Forwardfile', 'w') { |f| f.write(yaml) }
|
54
|
+
hash_to_forwardfile(:auth => 'username:password')
|
56
55
|
|
57
56
|
options = Forward::CLI.parse_forwardfile
|
58
57
|
options.has_key?(:auth).must_equal true
|
59
58
|
end
|
60
59
|
|
61
60
|
it 'exits if a Forwardfile does not parse to a Hash' do
|
62
|
-
|
63
|
-
File.open('Forwardfile', 'w') { |f| f.write(yaml) }
|
61
|
+
hash_to_forwardfile('username:password')
|
64
62
|
|
65
63
|
lambda {
|
66
64
|
dev_null { Forward::CLI.parse_forwardfile }
|
67
65
|
}.must_raise SystemExit
|
68
66
|
end
|
69
67
|
|
70
|
-
it 'overloads Forwardfile options via commandline' do
|
71
|
-
|
68
|
+
it 'overloads Forwardfile options via commandline options' do
|
69
|
+
hash_to_forwardfile(
|
70
|
+
:port => 8000,
|
71
|
+
:username => 'username',
|
72
|
+
:password => 'password',
|
73
|
+
:subdomain_prefix => 'foo'
|
74
|
+
)
|
75
|
+
args = [ '3000', '-a', 'example:secret', 'bar' ]
|
76
|
+
options = Forward::CLI.parse_args_and_options(args)
|
77
|
+
|
78
|
+
options[:port].must_equal 3000
|
79
|
+
options[:username].must_equal 'example'
|
80
|
+
options[:password].must_equal 'secret'
|
81
|
+
options[:subdomain_prefix].must_equal 'bar'
|
72
82
|
end
|
73
83
|
|
74
84
|
it 'doesnt exit on valid ports' do
|
@@ -114,3 +124,8 @@ describe Forward::CLI do
|
|
114
124
|
end
|
115
125
|
|
116
126
|
end
|
127
|
+
|
128
|
+
def hash_to_forwardfile(hash)
|
129
|
+
yaml = YAML.dump(hash)
|
130
|
+
File.open('Forwardfile', 'w') { |f| f.write(yaml) }
|
131
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forward
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|