working_man 0.0.6 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/working_man +45 -6
- data/features/working_man.feature +0 -11
- data/lib/working_man/version.rb +1 -1
- data/lib/working_man.rb +13 -36
- metadata +2 -2
data/bin/working_man
CHANGED
@@ -8,9 +8,8 @@ include Methadone::Main
|
|
8
8
|
include Methadone::CLILogging
|
9
9
|
|
10
10
|
main do |run_type|
|
11
|
-
|
12
|
-
|
13
|
-
# the options Hash
|
11
|
+
check_config!
|
12
|
+
|
14
13
|
case run_type
|
15
14
|
when "start"
|
16
15
|
WorkingMan.start_work
|
@@ -19,12 +18,52 @@ main do |run_type|
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
#
|
21
|
+
# Internal: Checks for a configuration file. If one is not found, message
|
22
|
+
# is printed to the console and system exits with status code "1"
|
23
|
+
#
|
24
|
+
# Examples:
|
25
|
+
#
|
26
|
+
# check_config!
|
27
|
+
#
|
28
|
+
# Returns true if everything passes
|
29
|
+
def check_config!
|
30
|
+
config_path = File.expand_path('~/.working_man.yml')
|
31
|
+
|
32
|
+
if File.exists?(config_path)
|
33
|
+
check_config_format(config_path)
|
34
|
+
return true
|
35
|
+
else
|
36
|
+
puts "No configuration found. Please configure which apps to start in #{config_path}"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
end
|
23
40
|
|
24
|
-
#
|
41
|
+
# Internal: Checks the format of the configuration file. If the configuration
|
42
|
+
# is blank, exits with status "2". If there are no apps, exits with status "3"
|
43
|
+
# If there are no URLs, prints a warning but continues with execution.
|
25
44
|
#
|
26
|
-
|
45
|
+
# Examples:
|
27
46
|
#
|
47
|
+
# check_config_format(config_path)
|
48
|
+
#
|
49
|
+
# Returns true if everything passes
|
50
|
+
def check_config_format(config_path)
|
51
|
+
$config = YAML::load(File.open(config_path))
|
52
|
+
|
53
|
+
if !$config
|
54
|
+
p "Nothing in configuration. Exiting..."
|
55
|
+
exit 2
|
56
|
+
elsif !$config['apps']
|
57
|
+
p "No applications in configuration. Exiting..."
|
58
|
+
exit 2
|
59
|
+
elsif !$config['urls']
|
60
|
+
p "WARN: No URLs in configuration"
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
description "WorkingMan starts and stops your work day"
|
66
|
+
|
28
67
|
# Require run_type
|
29
68
|
arg :run_type, "'start' or 'stop' your work day"
|
30
69
|
|
@@ -24,17 +24,6 @@ Scenario: Start work successfully with app and url
|
|
24
24
|
And I run `working_man start`
|
25
25
|
Then the output should contain "Work hard today"
|
26
26
|
And the exit status should be 0
|
27
|
-
|
28
|
-
Scenario: Start work successfully with app and no url
|
29
|
-
Given a file named "/tmp/fakehome/.working_man.yml" with:
|
30
|
-
"""
|
31
|
-
apps:
|
32
|
-
- 'Twitter'
|
33
|
-
urls:
|
34
|
-
"""
|
35
|
-
And I run `working_man start`
|
36
|
-
Then the output should contain "Work hard today"
|
37
|
-
And the exit status should be 0
|
38
27
|
|
39
28
|
Scenario: Start work unsuccessfully without any apps
|
40
29
|
Given a file named "/tmp/fakehome/.working_man.yml" with:
|
data/lib/working_man/version.rb
CHANGED
data/lib/working_man.rb
CHANGED
@@ -4,7 +4,7 @@ require "working_man/actions"
|
|
4
4
|
|
5
5
|
module WorkingMan
|
6
6
|
# Internal: Starts work day by calling WorkingMan::Actions#launch_applications,
|
7
|
-
# iterating through each app in
|
7
|
+
# iterating through each app in $config['apps']. It exits if there are no
|
8
8
|
# applications with error code 2. If there are no URLs, the program finishes
|
9
9
|
# successfully.
|
10
10
|
#
|
@@ -12,48 +12,25 @@ module WorkingMan
|
|
12
12
|
#
|
13
13
|
# WorkingMan.start_work
|
14
14
|
def self.start_work
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
p "No applications in configuration"
|
22
|
-
exit(2)
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
WorkingMan::Actions.open_urls(@config['urls'])
|
27
|
-
rescue NoMethodError
|
28
|
-
end
|
29
|
-
print "Work hard today!\n"
|
30
|
-
return true
|
31
|
-
else
|
32
|
-
puts "No configuration found. Please configure which apps to start in ~/.working_man.yml."
|
33
|
-
exit(1)
|
34
|
-
end
|
15
|
+
print "Starting work...\n"
|
16
|
+
|
17
|
+
WorkingMan::Actions.launch_applications($config['apps'])
|
18
|
+
WorkingMan::Actions.open_urls($config['urls'])
|
19
|
+
|
20
|
+
print "Work hard today!\n"
|
35
21
|
end
|
36
22
|
|
37
|
-
# Internal: Stop work iterates through the apps in
|
23
|
+
# Internal: Stop work iterates through the apps in $config['apps'], stopping
|
38
24
|
# each one
|
39
25
|
#
|
40
26
|
# Examples:
|
41
27
|
#
|
42
28
|
# WorkingMan.stop_work
|
43
29
|
def self.stop_work
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
rescue NoMethodError
|
50
|
-
p "No applications in configuration"
|
51
|
-
exit(2)
|
52
|
-
end
|
53
|
-
print "Have a great day!\n"
|
54
|
-
else
|
55
|
-
puts "No configuration found. Please configure which apps to start in ~/.working_man.yml."
|
56
|
-
exit(1)
|
57
|
-
end
|
30
|
+
print "Stopping work...\n"
|
31
|
+
|
32
|
+
WorkingMan::Actions.close_applications($config['apps'])
|
33
|
+
|
34
|
+
print "Have a great day!\n"
|
58
35
|
end
|
59
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: working_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.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: 2012-
|
12
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|