Class: WifiLogin::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/wifi_login/cli.rb

Constant Summary collapse

LAUNCH_AGENT_DIR =
"#{ENV['HOME']}/Library/LaunchAgents"
LAUNCH_AGENT_FILE =
"#{LAUNCH_AGENT_DIR}/jp.machu.wifi_login.plist"
LOG_DIR =
"#{ENV['HOME']}/Library/Logs/jp.machu.wifi_login"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



13
14
15
# File 'lib/wifi_login/cli.rb', line 13

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#installObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wifi_login/cli.rb', line 18

def install
  empty_directory LOG_DIR
  if WifiLogin.in_rbenv?
    template "templates/jp.machu.wifi_login.plist.rbenv.tt", "#{LAUNCH_AGENT_FILE}"
  else
    template "templates/jp.machu.wifi_login.plist.tt", "#{LAUNCH_AGENT_FILE}"
  end
  run "launchctl load #{LAUNCH_AGENT_FILE}"
  say
  say "Complete install. Please run `pit set docomo` to set your ID/Password.", Thor::Shell::Color::GREEN
  say "Example"
  say "--"
  say "id: your-id-spmode@docomo"
  say "password: your-password"
end

#loginObject



47
48
49
50
# File 'lib/wifi_login/cli.rb', line 47

def 
  success = WifiLogin.
  say 'Login success!', Thor::Shell::Color::GREEN if success
end

#ssidObject



42
43
44
# File 'lib/wifi_login/cli.rb', line 42

def ssid
  say "current SSID: #{WifiLogin.ssid}"
end

#uninstallObject



35
36
37
38
39
# File 'lib/wifi_login/cli.rb', line 35

def uninstall
  run "launchctl unload #{LAUNCH_AGENT_FILE}"
  return unless File.exist?(LAUNCH_AGENT_FILE)
  remove_file LAUNCH_AGENT_FILE
end

#versionObject



53
54
55
# File 'lib/wifi_login/cli.rb', line 53

def version
  say "wifi_login #{WifiLogin::VERSION}"
end