mac-wifi 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/RELEASE_NOTES.md +6 -0
- data/bin/mac-wifi +59 -53
- data/mac-wifi.gemspec +2 -2
- data/spec/mac-wifi_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c730b3171f9dba37b683b40cde3c4d40765001
|
4
|
+
data.tar.gz: 5660a6f765152ad8ac23a09f5f88084a4ec83d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 237050e6744bb80ae8c2f36053731db4a03c78cc1402b82a12479848ac6d20b16a032a48d8944e038fe026799f5c28b0991523108958182c083bde7c9e65bb4a
|
7
|
+
data.tar.gz: 57d380bc2392e40e2b78bc856b22be6c83ec388e70a365cc098b0b76084f1e5427dcd6fac64172dad7d300cf11b39f9883f4e67c894ad1430ca851ffaca926ba
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ output at the time of this writing:
|
|
19
19
|
```
|
20
20
|
➜ mac-wifi git:(master) ✗ ./mac-wifi h
|
21
21
|
|
22
|
-
Available commands are:
|
22
|
+
mac-wifi version 1.1.0 -- Available commands are:
|
23
23
|
|
24
24
|
ci - connected to Internet (not just wifi on)?
|
25
25
|
co[nnect] network-name - turns wifi on, connects to network-name
|
@@ -36,7 +36,7 @@ pa[ssword] network-name - shows password for preferred network-name
|
|
36
36
|
q[uit] - exits this program (interactive shell mode only)
|
37
37
|
r[m] network-name - removes network-name from the preferred networks list
|
38
38
|
s[hell] - opens an interactive pry shell (command line only)
|
39
|
-
t[ill] -
|
39
|
+
t[ill] - returns when the desired Internet connection state is true. Options:
|
40
40
|
'on'/:on or 'off'/:off
|
41
41
|
wait interval, in seconds (optional, defaults to 0.5 seconds)
|
42
42
|
w[ifion] - is the wifi on?
|
@@ -67,13 +67,15 @@ This is accomplished by the following command:
|
|
67
67
|
|
68
68
|
If you would like to see the Mac OS commands and their output, you can do so by setting the
|
69
69
|
environment variable MAC_WIFI_OPTS to include `-v` (for _verbose_).
|
70
|
-
This can be done in the following ways:
|
70
|
+
This can be done in the following ways (using the `info` command as an example):
|
71
71
|
|
72
72
|
```
|
73
73
|
export MAC_WIFI_OPTS=-v
|
74
74
|
./mac-wifi i
|
75
75
|
```
|
76
76
|
|
77
|
+
...or...
|
78
|
+
|
77
79
|
```
|
78
80
|
MAC_WIFI_OPTS=-v ./mac-wifi i
|
79
81
|
```
|
@@ -99,6 +101,9 @@ sudo gem install pry-coolline
|
|
99
101
|
|
100
102
|
### Using the Shell
|
101
103
|
|
104
|
+
**If the program immediately exits when you try to run the shell, try upgrading `pry` and `pry-byebug`.
|
105
|
+
This can be done by running `gem install pry; gem install pry-byebug`.**
|
106
|
+
|
102
107
|
The shell, invoked with the `s` command on the command line, provides an interactive
|
103
108
|
session. It can be useful when:
|
104
109
|
|
data/RELEASE_NOTES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## v1.2.0
|
2
|
+
|
3
|
+
* Fix: protect against using command strings shorter than minimum length
|
4
|
+
(e.g. 'c', when more chars are necessary to disambiguate multiple commands).
|
5
|
+
* Improvements in help text and readme.
|
6
|
+
|
1
7
|
## v1.1.0
|
2
8
|
|
3
9
|
* Sort available networks alphabetically, left justify ssid's.
|
data/bin/mac-wifi
CHANGED
@@ -26,11 +26,22 @@ require 'tempfile'
|
|
26
26
|
module MacWifi
|
27
27
|
|
28
28
|
# This version must be kept in sync with the version in the gemspec file.
|
29
|
-
VERSION = '1.
|
29
|
+
VERSION = '1.2.0'
|
30
30
|
|
31
31
|
|
32
32
|
class BaseModel
|
33
33
|
|
34
|
+
class OsCommandError < RuntimeError
|
35
|
+
attr_reader :exitstatus, :command, :text
|
36
|
+
|
37
|
+
def initialize(exitstatus, command, text)
|
38
|
+
@exitstatus = exitstatus
|
39
|
+
@command = command
|
40
|
+
@text = text
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
34
45
|
def initialize(verbose = false)
|
35
46
|
@verbose_mode = verbose
|
36
47
|
end
|
@@ -158,11 +169,7 @@ class BaseModel
|
|
158
169
|
# @return names of the networks that were removed (excludes non-preexisting networks)
|
159
170
|
def remove_preferred_networks(*network_names)
|
160
171
|
networks_to_remove = network_names & preferred_networks # exclude any nonexistent networks
|
161
|
-
networks_to_remove.each
|
162
|
-
run_os_command("sudo networksetup -removepreferredwirelessnetwork " +
|
163
|
-
"#{wifi_hardware_port} #{Shellwords.shellescape(name)}")
|
164
|
-
end
|
165
|
-
networks_to_remove
|
172
|
+
networks_to_remove.each { |name| remove_preferred_network(name) }
|
166
173
|
end
|
167
174
|
|
168
175
|
|
@@ -184,21 +191,21 @@ class BaseModel
|
|
184
191
|
|
185
192
|
wait_interval_in_secs ||= 0.5
|
186
193
|
|
187
|
-
|
194
|
+
finished_predicates = {
|
188
195
|
conn: -> { connected_to_internet? },
|
189
196
|
disc: -> { ! connected_to_internet? },
|
190
197
|
on: -> { wifi_on? },
|
191
198
|
off: -> { ! wifi_on? }
|
192
199
|
}
|
193
200
|
|
194
|
-
|
201
|
+
finished_predicate = finished_predicates[status]
|
195
202
|
|
196
|
-
if
|
197
|
-
raise ArgumentError.new("Option must be one of
|
203
|
+
if finished_predicate.nil?
|
204
|
+
raise ArgumentError.new("Option must be one of #{finished_predicates.keys.inspect}. Was: #{status.inspect}")
|
198
205
|
end
|
199
206
|
|
200
207
|
loop do
|
201
|
-
return if
|
208
|
+
return if finished_predicate.()
|
202
209
|
sleep(wait_interval_in_secs)
|
203
210
|
end
|
204
211
|
end
|
@@ -209,7 +216,7 @@ class MacOsModel < BaseModel
|
|
209
216
|
|
210
217
|
AIRPORT_CMD = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
|
211
218
|
|
212
|
-
def initialize(verbose)
|
219
|
+
def initialize(verbose = false)
|
213
220
|
super
|
214
221
|
end
|
215
222
|
|
@@ -295,7 +302,7 @@ class MacOsModel < BaseModel
|
|
295
302
|
# Returns true if wifi is on, else false.
|
296
303
|
def wifi_on?
|
297
304
|
lines = run_os_command("#{AIRPORT_CMD} -I").split("\n")
|
298
|
-
|
305
|
+
lines.grep("AirPort: Off").none?
|
299
306
|
end
|
300
307
|
|
301
308
|
|
@@ -406,17 +413,6 @@ class MacOsModel < BaseModel
|
|
406
413
|
end
|
407
414
|
|
408
415
|
|
409
|
-
class OsCommandError < RuntimeError
|
410
|
-
attr_reader :exitstatus, :command, :text
|
411
|
-
|
412
|
-
def initialize(exitstatus, command, text)
|
413
|
-
@exitstatus = exitstatus
|
414
|
-
@command = command
|
415
|
-
@text = text
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
|
420
416
|
def run_os_command(command)
|
421
417
|
output = `#{command} 2>&1` # join stderr with stdout
|
422
418
|
if $?.exitstatus != 0
|
@@ -451,6 +447,16 @@ class CommandLineInterface
|
|
451
447
|
|
452
448
|
attr_reader :model
|
453
449
|
|
450
|
+
class Command < Struct.new(:min_string, :max_string, :action); end
|
451
|
+
|
452
|
+
|
453
|
+
class BadCommandError < RuntimeError
|
454
|
+
def initialize(error_message)
|
455
|
+
super
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
|
454
460
|
# Help text to be used when requested by 'h' command, in case of unrecognized or nonexistent command, etc.
|
455
461
|
HELP_TEXT = "
|
456
462
|
mac-wifi version #{VERSION} -- Available commands are:
|
@@ -471,8 +477,8 @@ q[uit] - exits this program (interactive shell mode only)
|
|
471
477
|
r[m] network-name - removes network-name from the preferred networks list
|
472
478
|
s[hell] - opens an interactive pry shell (command line only)
|
473
479
|
t[ill] - returns when the desired Internet connection state is true. Options:
|
474
|
-
'on'/:on or '
|
475
|
-
wait interval, in seconds (optional, defaults to 0.5 seconds)
|
480
|
+
1) 'on'/:on, 'off'/:off, 'conn'/:conn, or 'disc'/:disc
|
481
|
+
2) wait interval, in seconds (optional, defaults to 0.5 seconds)
|
476
482
|
w[ifion] - is the wifi on?
|
477
483
|
x[it] - exits this program (interactive shell mode only)
|
478
484
|
|
@@ -485,17 +491,7 @@ When in interactive shell mode:
|
|
485
491
|
|
486
492
|
def initialize
|
487
493
|
@model = MacOsModel.new(verbose_mode)
|
488
|
-
@interactive_mode = false # will be true if/when user selects shell option on command line
|
489
|
-
end
|
490
|
-
|
491
|
-
|
492
|
-
class Command < Struct.new(:min_string, :max_string, :action); end
|
493
|
-
|
494
|
-
|
495
|
-
class BadCommandError < RuntimeError
|
496
|
-
def initialize(error_message)
|
497
|
-
super
|
498
|
-
end
|
494
|
+
@interactive_mode = false # will be changed to true if/when user selects shell option on command line
|
499
495
|
end
|
500
496
|
|
501
497
|
|
@@ -563,7 +559,8 @@ When in interactive shell mode:
|
|
563
559
|
begin
|
564
560
|
require 'pry'
|
565
561
|
rescue LoadError
|
566
|
-
puts "The 'pry' gem, required for running the shell, was not found.
|
562
|
+
puts "The 'pry' gem and/or one of its prerequisites, required for running the shell, was not found." +
|
563
|
+
" Please `gem install pry`."
|
567
564
|
exit(-1)
|
568
565
|
end
|
569
566
|
|
@@ -615,7 +612,7 @@ When in interactive shell mode:
|
|
615
612
|
else
|
616
613
|
print_help
|
617
614
|
raise BadCommandError.new(
|
618
|
-
|
615
|
+
%Q{Unrecognized command. Command was "#{command}" and options were #{options.inspect}.})
|
619
616
|
end
|
620
617
|
end
|
621
618
|
|
@@ -727,7 +724,7 @@ When in interactive shell mode:
|
|
727
724
|
|
728
725
|
def cmd_w
|
729
726
|
on = model.wifi_on?
|
730
|
-
puts "Wifi on
|
727
|
+
puts "Wifi on: #{on}" unless @interactive_mode
|
731
728
|
on
|
732
729
|
end
|
733
730
|
|
@@ -762,7 +759,12 @@ When in interactive shell mode:
|
|
762
759
|
|
763
760
|
|
764
761
|
def find_command_action(command_string)
|
765
|
-
result = commands.detect
|
762
|
+
result = commands.detect do |cmd|
|
763
|
+
cmd.max_string.start_with?(command_string) \
|
764
|
+
&& \
|
765
|
+
command_string.length >= cmd.min_string.length # e.g. 'c' by itself should not work
|
766
|
+
end
|
767
|
+
|
766
768
|
result ? result.action : nil
|
767
769
|
end
|
768
770
|
|
@@ -773,7 +775,7 @@ When in interactive shell mode:
|
|
773
775
|
process_command_line(ARGV[0], ARGV[1..-1])
|
774
776
|
rescue BadCommandError => error
|
775
777
|
separator_line = "#{'!' * 79}\n"
|
776
|
-
puts separator_line
|
778
|
+
puts '' << separator_line << error.to_s << "\n" << separator_line
|
777
779
|
exit(-1)
|
778
780
|
end
|
779
781
|
end
|
@@ -796,29 +798,33 @@ end
|
|
796
798
|
|
797
799
|
def running_as_script?
|
798
800
|
|
801
|
+
this_file = File.expand_path(__FILE__)
|
802
|
+
main_file = File.expand_path($0)
|
803
|
+
|
804
|
+
this_file_basename = File.basename(this_file)
|
805
|
+
main_file_basename = File.basename(main_file)
|
806
|
+
|
799
807
|
# Please enable this code and report its output if you report any issues with this method:
|
800
|
-
# puts "__FILE__ = #{
|
801
|
-
# puts "$0 = #{
|
808
|
+
# puts "__FILE__ = #{this_file}"
|
809
|
+
# puts "$0 = #{main_file}"
|
802
810
|
# puts "GEM_PATH = #{ENV['GEM_PATH']}"
|
803
811
|
|
804
|
-
return true if
|
805
|
-
return false if
|
812
|
+
return true if main_file == this_file
|
813
|
+
return false if main_file_basename != this_file_basename
|
806
814
|
|
807
815
|
# If here, then filespecs are different but have the same basename.
|
808
816
|
gem_paths = ENV['GEM_PATH'].split(File::PATH_SEPARATOR)
|
809
|
-
basename = File.basename($0)
|
810
817
|
gem_paths.any? do |path|
|
811
|
-
|
812
|
-
__file__up_4 = File.expand_path(File.join(
|
813
|
-
($0 ==
|
818
|
+
path_plus_basename = File.join(path, 'bin', main_file_basename)
|
819
|
+
__file__up_4 = File.expand_path(File.join(this_file, '..', '..', '..', '..'))
|
820
|
+
($0 == path_plus_basename) && (path == __file__up_4)
|
814
821
|
end
|
815
822
|
end
|
816
823
|
|
817
824
|
|
818
825
|
def assert_os_is_mac_os
|
819
|
-
|
820
|
-
|
821
|
-
raise "This program currently works only on Mac OS. Platform is '#{uname}'."
|
826
|
+
unless /darwin/ === RbConfig::CONFIG["host_os"] # e.g. "darwin16.4.0"
|
827
|
+
raise "This program currently works only on Mac OS. Platform is '#{RbConfig::CONFIG["host_os"]}'."
|
822
828
|
end
|
823
829
|
end
|
824
830
|
|
data/mac-wifi.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
#
|
3
|
-
VERSION = '1.
|
2
|
+
# When changing the version, also change the version and the help text in the README.
|
3
|
+
VERSION = '1.2.0'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "mac-wifi"
|
data/spec/mac-wifi_spec.rb
CHANGED
@@ -9,10 +9,10 @@ load File.join(File.dirname(__FILE__), '..', 'bin', 'mac-wifi')
|
|
9
9
|
|
10
10
|
module MacWifi
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe MacOsModel do
|
13
13
|
|
14
14
|
|
15
|
-
subject {
|
15
|
+
subject { MacOsModel.new }
|
16
16
|
|
17
17
|
context 'turning wifi on and off' do
|
18
18
|
it 'can turn wifi on' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mac-wifi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Bennett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A command line interface for managing wifi on a Mac.
|
14
14
|
email:
|