enzyme 0.1.4 → 1.0.0.beta01

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Haydn Ewers
1
+ Copyright (c) 2012 Katalyst Interactive
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,27 @@
1
+ Enzyme
2
+ ======
3
+
4
+ Katayst Interactive's project collaboration tool.
5
+
6
+ Getting Started
7
+ ---------------
8
+
9
+ ### Installing
10
+
11
+ gem install enzyme
12
+
13
+
14
+ Contributing
15
+ ------------
16
+
17
+ 1. Check out the develop branch to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
18
+ 2. Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
19
+ 3. Fork the project.
20
+ 4. Start a feature/<name> branch.
21
+ 5. Commit and push until you are happy with your contribution.
22
+ 6. Please try not to mess with the Rakefile or version.
23
+
24
+ Copyright
25
+ ---------
26
+
27
+ Copyright (c) 2012 Katalyst Interactive. See LICENSE.txt for further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 1.0.0.beta01
data/bin/enzyme CHANGED
@@ -3,10 +3,9 @@
3
3
  lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
5
 
6
- require 'setup'
7
6
  require 'enzyme'
8
7
 
9
8
  # Require all commands in the commands directory.
10
9
  Dir["#{lib_dir}/commands/*.rb"].each {|file| require "commands/"+File.basename(file, ".rb") }
11
10
 
12
- Enzyme.run()
11
+ Enzyme.run()
@@ -1,75 +1,103 @@
1
- require 'yaml'
2
- require 'hash'
3
1
  require 'enzyme'
4
2
 
5
3
  module Config extend self
6
4
 
7
- GLOBAL_FILENAME = "#{ENV['HOME']}/.enzyme.yml"
8
- PROJECT_FILENAME = "./.enzyme.yml"
9
-
10
5
  def run()
11
- global = ARGV.delete('--global')
12
- ARGV.reject { |x| x.start_with?("-") }
6
+ file = ['--global', '--organisation', '--project'].keep_if { |x| ARGV.delete(x) }.last.to_s[/[a-z]+$/] || nil
7
+ ARGV.each { |x| raise UnknownOption.new(x) if x.start_with?("-") }
13
8
  key = ARGV.shift
14
9
  value = ARGV.shift
10
+ ARGV.each { |x| raise UnknownArgument.new(x) }
15
11
 
16
12
  unless value === nil
17
- set(key, value, global)
13
+ set(key, value, file)
14
+ puts "Set '#{key}' to '#{value}' in '#{$system_settings.config[file].path}'."
18
15
  else
19
- val = get(key)
20
- if val.is_a?(Array) || val.is_a?(Hash) || val.is_a?(Settings)
16
+ val = get(key, file)
17
+ if val.is_a?(Array) || val.is_a?(Hash)
21
18
  puts val.to_hash.to_yaml
22
19
  else
23
20
  puts val.to_s
24
21
  end
25
22
  end
23
+ puts
24
+ end
25
+
26
+ # Checks if the given setting has a value.
27
+ # - key: The setting to check.
28
+ def is_set?(key)
29
+ (get(key).nil? || get(key).empty?) ? false : true
26
30
  end
27
31
 
28
- def get(key)
29
- s = $settings
30
- key.split('.').each { |o| s = s[o] } if key
32
+ # Gets the value of a given setting.
33
+ # - key: The setting to get.
34
+ # - file: If set, specifies which config file to get the setting from.
35
+ def get(key, file=nil)
36
+ s = file ? (YAML.load_file($system_settings.config[file.to_s].path) || {}) : $settings
37
+ key.to_s.split('.').each do |o|
38
+ return nil if s[o].nil?
39
+ s = s[o]
40
+ end
31
41
  s
32
42
  end
33
43
 
34
- def set(key, value, global=false)
35
- filename = global ? GLOBAL_FILENAME : PROJECT_FILENAME
36
- settings = YAML.load_file(filename) || {}
44
+ # Sets the value of the given setting.
45
+ # - key: The setting to set.
46
+ # - value: The value to set the setting to.
47
+ # - file: Which config file to set the setting in.
48
+ def set(key, value, file=nil)
49
+ if file.nil?
50
+ file = $system_settings.config.project.exists ? "project" : "global"
51
+ else
52
+ file = file.nil? ? 'global' : file.to_s
53
+ end
54
+
55
+ # Bail if the config file doesn't exist.
56
+ raise ConfigFileNotFound.new($system_settings.config[file].path) unless $system_settings.config[file].exists
37
57
 
38
58
  # FIXME: This could be simplified... heaps.
39
- newSettings = {}
40
- n = newSettings
59
+ new_settings = { 'enzyme_version' => $system_settings.version }
60
+ current_hash = new_settings
41
61
  keys = key.to_s.split(".")
42
- keys.each do |k|
43
- k = k.to_i if k == k.to_i.to_s
44
- n[k] = (k == keys.last) ? value : {}
45
- n = n[k]
62
+ keys.each do |key|
63
+ key = key.to_i if key.is_i?
64
+ current_hash[key] = (key == keys.last) ? value : {}
65
+ current_hash = current_hash[key]
46
66
  end
47
67
 
48
- settings = settings.deep_merge(newSettings)
68
+ $settings = $settings.deep_merge(new_settings)
69
+
70
+ # Reload the settings to avoid including temporary settings.
71
+ settings = YAML.load_file($system_settings.config[file].path) || {}
72
+ # Merge in the new settings.
73
+ settings = settings.deep_merge(new_settings)
74
+
75
+ # Save the settings to the config file.
76
+ write($system_settings.config[file].path, settings)
77
+ end
49
78
 
50
- File.open(filename, "w") { |f| f.write(settings.to_yaml) }
79
+ def write(path, settings)
80
+ File.open(path, "w") do |f|
81
+ f.write("\# Generated by Enzyme.\n")
82
+ f.write(settings.to_yaml)
83
+ end
51
84
  end
52
85
 
53
86
  end
54
87
 
55
- Enzyme.register(Config) do
56
- puts 'CONFIG COMMAND'
57
- puts '--------------'
58
- puts ''
59
- puts '### SYNOPSIS'
60
- puts ''
61
- puts ' enzyme config [<key> [<value> [--global]]]'
62
- puts ''
63
- puts '### EXAMPLES'
64
- puts ''
65
- puts ' enzyme config user dave --global'
66
- puts ''
67
- puts ' enzyme config user'
68
- puts ' > dave'
69
- puts ''
70
- puts ' enzyme config project_name my_project'
71
- puts ''
72
- puts ' enzyme config project_name'
73
- puts ' > my_project'
74
- puts ''
75
- end
88
+ Enzyme.register('config', Config) do
89
+ puts "#{$format.bold}SYNOPSIS#{$format.normal}"
90
+ puts ' enzyme config [<key> [<value> [--global]]]'
91
+ puts
92
+ puts "#{$format.bold}EXAMPLES#{$format.normal}"
93
+ puts ' enzyme config user dave --global'
94
+ puts
95
+ puts ' enzyme config user'
96
+ puts ' > dave'
97
+ puts
98
+ puts ' enzyme config project_name my_project'
99
+ puts
100
+ puts ' enzyme config project_name'
101
+ puts ' > my_project'
102
+ puts
103
+ end
@@ -1,136 +1,100 @@
1
1
  require 'enzyme'
2
2
  require 'commands/config'
3
+ require 'commands/join'
3
4
 
4
5
  module Create extend self
5
6
 
6
7
  def run()
7
- ARGV.reject { |x| x.start_with?("-") }
8
- @@project_name = ARGV.shift
9
- @@project_type = ARGV.shift
10
-
11
- if @@project_name
12
- if @@project_type
13
- case @@project_type.to_sym
14
- when :pms
15
- pms
16
- when :koi
17
- koi
18
- else
19
- raise "Unknown project type `#{project_type}`."
20
- end
21
- else
22
- base
23
- end
24
- puts
25
- puts "Complete."
26
- puts
27
- else
28
- raise "A project name must be given. For example: `enzyme create project_name`"
29
- end
30
- end
31
-
32
- def base
33
- raise "The `projects_directory` setting is not set. Set it using `enzyme config projects_directory \"/Users/me/Projects\" --global`." unless $settings.projects_directory
34
- raise "The `sync.shared_directory` setting is not set. Set it using `enzyme config sync.shared_directory \"shared\" --global`." unless $settings.sync.shared_directory
35
- raise "The `user` setting is not set. Set it using `enzyme config user \"me\" --global`." unless $settings.user
36
-
37
- @@project_name = @@project_name+'_'+Time.now.strftime('%y%m') unless @@project_name =~ /^.+_\d{4}$/
38
-
39
- puts
40
- puts "Creating the '#{@@project_name}' project at '#{$settings.projects_directory}/#{@@project_name}'..."
41
- puts
8
+ skip_join = !!ARGV.delete("--skip-join")
9
+ ARGV.each { |x| raise UnknownOption.new(x) if x.start_with?("-") }
10
+ project_name = ARGV.shift
11
+ ARGV.each { |x| raise UnknownArgument.new(x) }
42
12
 
43
- system "mkdir #{$settings.projects_directory}/#{@@project_name}"
44
- # TODO: Move the resources directory and it's content to the sync command. Create shouldn't be responsible for it.
45
- system "mkdir #{$settings.projects_directory}/#{@@project_name}/resources"
46
- system "mkdir #{$settings.projects_directory}/#{@@project_name}/resources/#{$settings.sync.shared_directory}"
47
- system "mkdir #{$settings.projects_directory}/#{@@project_name}/resources/#{$settings.user}"
48
- system "touch #{$settings.projects_directory}/#{@@project_name}/.enzyme.yml"
13
+ raise ArgumentMissing.new("project_name") unless project_name
49
14
 
50
- Dir.chdir("#{$settings.projects_directory}/#{@@project_name}")
15
+ create(project_name)
51
16
 
52
- Config.set('project_name', @@project_name)
53
- Config.set('project_type', nil)
17
+ Join.join(project_name) unless skip_join
54
18
  end
55
19
 
56
- def koi
57
- raise "The `projects_directory` setting is not set. Set it using `enzyme config projects_directory \"/Users/me/Projects\" --global`." unless $settings.projects_directory
58
- raise "The `github.user` setting is not set. Set it using `enzyme config github.user \"me\" --global`." unless $settings.github.user
59
- raise "The `github.token` setting is not set. Set it using `enzyme config github.token \"0123456789abcdef0123456789abcdef\" --global`." unless $settings.github.token
20
+ def create(project_name)
21
+ raise SyncServerRequired.new unless $system_settings.sync_server.exists
22
+ raise SettingMissing.new("sync.projects_directory", "path/to/directory", "organisation") unless $settings.sync.projects_directory
60
23
 
61
- base
24
+ directory = "#{$system_settings.sync_server.path}/#{$settings.sync.projects_directory}/#{project_name}"
62
25
 
63
- Config.set('project_type', 'koi')
26
+ # If the project already exists, raise an error.
27
+ raise ProjectAlreadyExists.new(directory) if File.directory?(directory)
64
28
 
65
- puts
66
- puts "Downloading the latest version of Koi from 'https://github.com/katalyst/koi_cms/zipball/master'..."
67
- puts
68
-
69
- system "curl -o '/tmp/#{@@project_name}.zip' -F 'login=#{$settings.github.user}' -F 'token=#{$settings.github.token}' -L 'https://github.com/katalyst/koi_cms/zipball/master'"
70
-
71
- puts
72
- puts 'Extracting...'
73
- puts
29
+ create_repo directory, [ "*", "!.enzyme.yml", "!.gitignore" ]
30
+ Config.write("#{directory}/.enzyme.yml", { "project_name" => project_name })
31
+ commit_repo directory
32
+ detach_repo directory
74
33
 
75
- system "unzip '/tmp/#{@@project_name}.zip' -d '/tmp/#{@@project_name}.temp'"
76
- system "rm '/tmp/#{@@project_name}.zip'"
34
+ create_repo "#{directory}/shared"
35
+ commit_repo "#{directory}/shared"
36
+ detach_repo "#{directory}/shared"
77
37
 
78
- extracted_dir = Dir.entries("/tmp/#{@@project_name}.temp")[2]
38
+ create_repo "#{directory}/working"
39
+ commit_repo "#{directory}/working"
40
+ detach_repo "#{directory}/working"
79
41
 
42
+ puts "Created remote project at:"
80
43
  puts
81
- puts "Copying to '#{$settings.projects_directory}/#{@@project_name}/'..."
44
+ puts " #{directory}"
82
45
  puts
83
-
84
- system "mv /tmp/#{@@project_name}.temp/#{extracted_dir}/* #{$settings.projects_directory}/#{@@project_name}"
85
- system "rm -r '/tmp/#{@@project_name}.temp'"
86
46
  end
87
47
 
88
- def pms
89
- raise "The `projects_directory` setting is not set. Set it using `enzyme config projects_directory \"/Users/me/Projects\" --global`." unless $settings.projects_directory
90
- raise "The `github.user` setting is not set. Set it using `enzyme config github.user \"me\" --global`." unless $settings.github.user
91
- raise "The `github.token` setting is not set. Set it using `enzyme config github.token \"0123456789abcdef0123456789abcdef\" --global`." unless $settings.github.token
48
+ def create_repo(path, gitignore=[])
49
+ # Create the project's directory.
50
+ system "mkdir -p #{path} > /dev/null"
92
51
 
93
- base
52
+ # Change into the directory.
53
+ system "cd #{path} > /dev/null"
54
+ Dir.chdir(path)
94
55
 
95
- Config.set('project_type', 'pms')
56
+ # Gitify.
57
+ system "git init > /dev/null"
58
+ system "echo '#{gitignore.join("\n")}' > .gitignore"
59
+ end
96
60
 
97
- puts
98
- puts "Downloading v0.4.2alpha03 of the PMS from 'https://github.com/katalyst/pms/zipball/v0.4.2alpha03'..."
99
- puts
61
+ def commit_repo(path)
62
+ # Create the project's directory.
63
+ system "mkdir -p #{path} > /dev/null"
100
64
 
101
- system "curl -o '/tmp/#{@@project_name}.zip' -F 'login=#{$settings.github.user}' -F 'token=#{$settings.github.token}' -L 'https://github.com/katalyst/pms/zipball/v0.4.2alpha03'"
65
+ # Change into the directory.
66
+ system "cd #{path} > /dev/null"
67
+ Dir.chdir(path)
102
68
 
103
- puts
104
- puts 'Extracting...'
105
- puts
69
+ # Gitify.
70
+ system "git add . > /dev/null"
71
+ system "git commit -m 'Initial commit.' > /dev/null"
72
+ end
106
73
 
107
- system "unzip '/tmp/#{@@project_name}.zip' -d '/tmp/#{@@project_name}.temp'"
108
- system "rm '/tmp/#{@@project_name}.zip'"
74
+ def detach_repo(path)
75
+ # Create the project's directory.
76
+ system "mkdir -p #{path} > /dev/null"
109
77
 
110
- extracted_dir = Dir.entries("/tmp/#{@@project_name}.temp")[2]
78
+ # Change into the directory.
79
+ system "cd #{path} > /dev/null"
80
+ Dir.chdir(path)
111
81
 
112
- puts
113
- puts "Copying to '#{$settings.projects_directory}/#{@@project_name}/'..."
114
- puts
115
-
116
- system "mv /tmp/#{@@project_name}.temp/#{extracted_dir}/* #{$settings.projects_directory}/#{@@project_name}"
117
- system "rm -r '/tmp/#{@@project_name}.temp'"
82
+ # Gitify.
83
+ system "git checkout -q --detach > /dev/null"
118
84
  end
119
85
 
120
86
  end
121
87
 
122
- Enzyme.register(Create) do
123
- puts 'CREATE COMMAND'
124
- puts '--------------'
125
- puts ''
126
- puts '### SYNOPSIS'
127
- puts ''
128
- puts ' enzyme create <project_name> [pms | koi]'
129
- puts ''
130
- puts '### EXAMPLES'
131
- puts ''
132
- puts ' enzyme create my_project pms'
133
- puts ''
134
- puts ' enzyme create another_project koi'
135
- puts ''
136
- end
88
+ Enzyme.register('create', Create) do
89
+ puts "#{$format.bold}SYNOPSIS#{$format.normal}"
90
+ puts ' enzyme create <project_name>'
91
+ puts
92
+ puts "#{$format.bold}EXAMPLES#{$format.normal}"
93
+ puts ' > enzyme create example-project'
94
+ puts ' '
95
+ puts ' Created local project at:'
96
+ puts ' '
97
+ puts ' `/Users/jane/Projects/example-project`'
98
+ puts ' '
99
+ puts
100
+ end
@@ -0,0 +1,59 @@
1
+ require 'enzyme'
2
+ require 'commands/config'
3
+
4
+ module Join extend self
5
+
6
+ def run()
7
+ # --skip-shared
8
+ # --skip-working
9
+ ARGV.each { |x| raise UnknownOption.new(x) if x.start_with?("-") }
10
+ project_name = ARGV.shift
11
+ ARGV.each { |x| raise UnknownArgument.new(x) }
12
+
13
+ raise ArgumentMissing.new("project_name") unless project_name
14
+
15
+ join(project_name)
16
+ end
17
+
18
+ def join(project_name)
19
+ raise SyncServerRequired.new unless $system_settings.sync_server.exists
20
+ raise SettingMissing.new("projects_directory") unless $settings.projects_directory
21
+ raise SettingMissing.new("sync.projects_directory") unless $settings.sync.projects_directory
22
+ raise SettingMissing.new("short_name") unless $settings.short_name
23
+
24
+ local_directory = "#{$settings.projects_directory}/#{project_name}"
25
+ remote_directory = "#{$system_settings.sync_server.path}/#{$settings.sync.projects_directory}/#{project_name}"
26
+
27
+ # If the local project directory already exists, raise an error.
28
+ raise ProjectAlreadyExists.new(local_directory) if File.directory?(local_directory)
29
+
30
+ # If the remote project directory doesn't exists, raise an error.
31
+ raise CannotFindProject.new(remote_directory) unless File.directory?(remote_directory)
32
+
33
+ # Clone the shared and working directories.
34
+ system "git clone -q #{remote_directory} #{local_directory}"
35
+ system "cd #{local_directory}; git checkout -q master;"
36
+ system "git clone -q #{remote_directory}/shared #{local_directory}/shared"
37
+ system "cd #{local_directory}/shared; git checkout -q master;"
38
+ system "git clone -q #{remote_directory}/working #{local_directory}/working"
39
+ system "cd #{local_directory}/working; git checkout -q master;"
40
+
41
+ # Create the user's working directory unless it's already there.
42
+ system "mkdir #{local_directory}/working/#{$settings.short_name}" unless File.directory?("#{local_directory}/working/#{$settings.short_name}")
43
+
44
+ puts "Joined the '#{project_name}' project at:"
45
+ puts
46
+ puts " #{local_directory}"
47
+ puts
48
+ end
49
+
50
+ end
51
+
52
+ Enzyme.register('join', Join) do
53
+ puts "#{$format.bold}SYNOPSIS#{$format.normal}"
54
+ puts ' enzyme join <project_name>'
55
+ puts
56
+ puts "#{$format.bold}EXAMPLES#{$format.normal}"
57
+ puts ' enzyme join abc'
58
+ puts
59
+ end
@@ -2,48 +2,76 @@ require 'enzyme'
2
2
 
3
3
  module Sync extend self
4
4
 
5
- def run()
6
- ARGV.reject { |x| x.start_with?("-") }
5
+ def run
6
+ skip_shared = !!ARGV.delete("--skip-shared")
7
+ skip_working = !!ARGV.delete("--skip-working")
8
+ ARGV.each { |x| raise UnknownOption.new(x) if x.start_with?("-") }
7
9
  project_name = ARGV.shift || $settings.project_name
10
+ ARGV.each { |x| raise UnknownArgument.new(x) }
8
11
 
9
- raise "No project name specified. Ensure you're in the project's directory or set it specifically. Run `enzyme help sync` for help." unless project_name
10
- raise "The #{project_name} project could not be found." unless File.exist?("#{$settings.projects_directory}/#{project_name}")
11
- raise "The `sync.share_name` setting is not set. Set it using `enzyme config sync.share_name \"Share Name\" --global`." unless $settings.sync.share_name
12
- raise "The `sync.host` setting is not set. Set it using `enzyme config sync.host \"Host._afpovertcp._tcp.local\" --global`." unless $settings.sync.host
13
- raise "The `sync.projects_directory` setting is not set. Set it using `enzyme config sync.projects_directory \"My Projects Directory\" --global`." unless $settings.sync.projects_directory
14
- raise "The `user` setting is not set. Set it using `enzyme config user \"my_directory\" --global`." unless $settings.user
15
- raise "The `sync.shared_directory` setting is not set. Set it using `enzyme config sync.shared_directory \"our_shared_directory\" --global`." unless $settings.sync.shared_directory
16
-
17
- # Mount the network volume. Only works on OS X.
18
- system "mkdir \"/Volumes/#{$settings.sync.share_name}\""
19
- system "mount -t afp \"afp://#{$settings.sync.host}/#{$settings.sync.share_name}\" \"/Volumes/#{$settings.sync.share_name}\""
20
- system "mkdir \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}\""
21
- # Pull.
22
- system "rsync -aH --stats -v -u --progress --exclude '#{$settings.user}/**' \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}/\" '#{$settings.projects_directory}/#{project_name}/resources/'"
23
- # Push.
24
- system "rsync -aH --stats -v -u --progress --include '*/' --include '#{$settings.sync.shared_directory}/**' --include '#{$settings.user}/**' --exclude '*' '#{$settings.projects_directory}/#{project_name}/resources/' \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}/\""
12
+ raise ArgumentOrSettingMissing.new("project_name", "project_name") unless project_name
13
+ raise SettingMissing.new("projects_directory") unless $settings.projects_directory
14
+
15
+ directory = "#{$settings.projects_directory}/#{project_name}"
16
+
17
+ raise CannotFindProject.new(directory) unless File.directory?(directory)
18
+
19
+ # BASE
20
+
21
+ system "cd #{directory}"
22
+ Dir.chdir("#{directory}")
23
+
24
+ system "git add .enzyme.yml > /dev/null"
25
+ system "git commit -m 'Enzyme sync.'"
26
+ system "git pull > /dev/null"
27
+ system "git push > /dev/null"
28
+
29
+ # SHARED
30
+
31
+ unless skip_shared
32
+ system "cd #{directory}/shared"
33
+ Dir.chdir("#{directory}/shared")
34
+
35
+ system "git checkout -q . > /dev/null"
36
+ system "git add . > /dev/null"
37
+ system "git commit -m 'Enzyme sync.'"
38
+ system "git pull > /dev/null"
39
+ system "git push > /dev/null"
40
+ end
41
+
42
+ # WORKING
43
+
44
+ system "cd #{directory}/working"
45
+ Dir.chdir("#{directory}/working")
46
+
47
+ system "git add #{$settings.short_name} > /dev/null"
48
+ system "git add -u > /dev/null"
49
+ system "git commit -a -m 'Enzyme sync.'"
50
+ system "git clean -fd > /dev/null"
51
+ system "git pull > /dev/null"
52
+ system "git push > /dev/null"
25
53
  end
26
54
 
27
55
  end
28
56
 
29
- Enzyme.register(Sync) do
30
- puts 'SYNC COMMAND'
31
- puts '------------'
32
- puts ''
33
- puts '### SYNOPSIS'
34
- puts ''
35
- puts ' enzyme sync [<project_name>]'
36
- puts ''
37
- puts '### OPTIONS'
38
- puts ''
39
- puts '<project_name>'
40
- puts ': The name of the project to sync. If the working directory is the root of a project this option does not need to be passed.'
41
- puts ''
42
- puts '### EXAMPLES'
43
- puts ''
44
- puts ' cd ~/Projects/my_project'
45
- puts ' enzyme sync'
46
- puts ''
47
- puts ' enzyme sync another_project'
48
- puts ''
49
- end
57
+ Enzyme.register('sync', Sync) do
58
+ puts "#{$format.bold}SYNOPSIS#{$format.normal}"
59
+ puts ' enzyme sync [<project_name>] [--discard-changes] [--init]'
60
+ puts
61
+ puts "#{$format.bold}DESCRIPTION#{$format.normal}"
62
+ puts ' Options:'
63
+ puts
64
+ puts " #{$format.bold}<project_name>#{$format.normal}"
65
+ puts ' The name of the project to sync. If the working directory is the root of a project this option does not need to be passed.'
66
+ puts
67
+ puts "#{$format.bold}EXAMPLES#{$format.normal}"
68
+ puts ' You can run sync like this:'
69
+ puts
70
+ puts ' enzyme sync another_project'
71
+ puts ' If you specify a project you can run sync from anywhere.'
72
+ puts
73
+ puts ' cd ~/Projects/my_project'
74
+ puts ' enzyme sync'
75
+ puts ' When the working directory is the root of a project you can run sync without any arguments.'
76
+ puts
77
+ end
@@ -1,21 +1,29 @@
1
+ require 'setup'
2
+
1
3
  module Enzyme extend self
2
4
 
3
5
  @@commands = {}
4
6
 
5
7
  def run
6
8
  # Only shift the first argument off the ARGV if help flags haven't been passed.
7
- command = (ARGV.delete("-h") || ARGV.delete("--help")) ? 'help' : (ARGV.shift || 'help')
9
+ command = (ARGV.delete("-h") || ARGV.delete("--help")) ? 'help' : ARGV.shift
10
+
11
+ puts
8
12
 
9
13
  # Show info, help or run the requested command if it has been registered.
10
14
  begin
11
- if command.eql?('help')
15
+ if command.nil?
16
+ info
17
+ help
18
+ elsif command.eql?('info')
19
+ info
20
+ elsif command.eql?('help')
12
21
  help
13
22
  else
14
- if @@commands.include?(command.to_s.downcase)
15
- @@commands[command.to_s.downcase][:class].run()
23
+ if @@commands.include?(command)
24
+ @@commands[command][:class].run
16
25
  else
17
- error("Unable to find command `#{command}`.")
18
- help
26
+ raise UnknownCommand.new(command)
19
27
  end
20
28
  end
21
29
  rescue StandardError => e
@@ -24,65 +32,66 @@ module Enzyme extend self
24
32
  end
25
33
 
26
34
  def info
27
- puts 'ENZYME'
28
- puts '======'
29
- puts ''
30
- puts 'Katalyst\'s project collaboration tool.'
31
- puts ''
32
- puts 'Version: '+$version
33
- puts ''
35
+ puts '+-------------------------------------------------+'
36
+ puts '| ##### ## ## ###### ## ## ## ## ##### |'
37
+ puts '| ## ### ## ## ## ## ### ### ## |'
38
+ puts '| ##### ###### ## ### ######## ##### |'
39
+ puts '| ## ## ### ## ## ## ## ## ## |'
40
+ puts '| ##### ## ## ###### ## ## ## ##### |'
41
+ puts '+-------------------------------------------------+'
42
+ puts
43
+ puts "#{$format.bold}DESCRIPTION#{$format.normal}"
44
+ puts ' Katalyst\'s project collaboration tool.'
45
+ puts
46
+ puts "#{$format.bold}VERSION#{$format.normal}"
47
+ puts " #{$system_settings.version}"
48
+ puts
34
49
  end
35
50
 
36
51
  def help
37
52
  ARGV.reject { |x| x.start_with?("-") }
38
53
  command = ARGV.shift
39
54
 
40
- info
41
-
42
55
  if command
43
56
  if @@commands.include?(command.to_s.downcase)
44
57
  @@commands[command.to_s.downcase][:help].call
45
58
  else
46
- error("No help available for `#{name}`.")
59
+ error("No help available for `#{command}`.")
47
60
  end
48
61
  else
49
- puts 'USAGE'
50
- puts '-----'
51
- puts ''
52
- puts '### Commands'
53
- puts ''
54
- puts ' enzyme config [<key> [<value> [--global]]]'
55
- puts ' enzyme create <project_name> [pms | koi]'
56
- # puts ' enzyme join <project_name>'
57
- puts ' enzyme sync [<project_name>]'
58
- puts ''
59
- puts '### Help'
60
- puts ''
61
- puts ' enzyme help [<command>]'
62
- puts ' enzyme [<command>] --help'
63
- puts ' enzyme [<command>] -h'
64
- puts ''
65
- puts '### Debugging'
66
- puts ''
67
- puts 'Use `--trace` at anytime to get full stacktraces.'
68
- puts ''
62
+ puts "#{$format.bold}SYNOPSIS#{$format.normal}"
63
+ puts ' enzyme <command> [<options>]'
64
+ puts
65
+ puts "#{$format.bold}HELP#{$format.normal}"
66
+ puts ' enzyme help [<command>]'
67
+ puts ' enzyme [<command>] --help'
68
+ puts ' enzyme [<command>] -h'
69
+ puts
70
+ puts "#{$format.bold}COMMANDS#{$format.normal}"
71
+
72
+ ([ "info" ]+@@commands.keys).sort.each { |command| puts " #{command}" }
73
+
74
+ puts
75
+ puts "#{$format.bold}DEBUGGING#{$format.normal}"
76
+ puts ' Use `--trace` at anytime to get full stacktraces.'
77
+ puts ' Use `--skip-sync-server` to prevent the sync server from mounting automatically.'
78
+ puts
69
79
  end
70
80
  end
71
81
 
72
82
  def error(error)
73
- if $trace_errors && error.is_a?(StandardError)
83
+ if $system_settings.trace_errors
74
84
  raise error
75
85
  else
76
- puts 'ERROR'
77
- puts '-----'
78
- puts ''
79
- puts '> '+error
80
- puts ''
86
+ puts "#{$format.bold}ERROR: #{error}#{$format.normal}"
87
+ puts
88
+ puts ' Run `enzyme help` for help or use the `--trace` option to get a full stacktrace.'
89
+ puts
81
90
  end
82
91
  end
83
92
 
84
- def register(command_class, &block)
85
- @@commands[command_class.to_s.downcase] = { :class => command_class, :help => block }
93
+ def register(command, command_class, &block)
94
+ @@commands[command] = { :class => command_class, :help => block }
86
95
  end
87
96
 
88
- end
97
+ end
@@ -0,0 +1,79 @@
1
+ class UnknownOption < StandardError
2
+
3
+ def initialize(name)
4
+ super("Unknown option '#{name}'.")
5
+ end
6
+
7
+ end
8
+
9
+ class UnknownArgument < StandardError
10
+
11
+ def initialize(name)
12
+ super("Unknown argument '#{name}'.")
13
+ end
14
+
15
+ end
16
+
17
+ class ArgumentMissing < StandardError
18
+
19
+ def initialize(name)
20
+ super("The '#{name}' argument is required.")
21
+ end
22
+
23
+ end
24
+
25
+ class SettingMissing < StandardError
26
+
27
+ def initialize(name, suggested_value="value", config_file="global")
28
+ super("The `#{name}` setting is not set. Set it using `enzyme config #{name} '#{suggested_value}' --#{config_file}`.")
29
+ end
30
+
31
+ end
32
+
33
+ class ConfigFileNotFound < StandardError
34
+
35
+ def initialize(path)
36
+ super("Config file could not be found at '#{path}'.")
37
+ end
38
+
39
+ end
40
+
41
+ class SyncServerRequired < StandardError
42
+
43
+ def initialize
44
+ super("Sync server could not be found. Make sure the `sync.share_name` & `sync.host_name` settings are correct and you are connected to the right network.")
45
+ end
46
+
47
+ end
48
+
49
+ class ProjectAlreadyExists < StandardError
50
+
51
+ def initialize(path)
52
+ super("A project already exists at '#{path}'.")
53
+ end
54
+
55
+ end
56
+
57
+ class CannotFindProject < StandardError
58
+
59
+ def initialize(path)
60
+ super("Cannot find a project at '#{path}'.")
61
+ end
62
+
63
+ end
64
+
65
+ class ArgumentOrSettingMissing < StandardError
66
+
67
+ def initialize(argument_name, setting_name)
68
+ super("The '#{argument_name}' argument was not provided and the '#{setting_name}' setting is not set.")
69
+ end
70
+
71
+ end
72
+
73
+ class UnknownCommand < StandardError
74
+
75
+ def initialize(command)
76
+ super("Unable to find command `#{command}`.")
77
+ end
78
+
79
+ end
@@ -1,8 +1,19 @@
1
- # From: http://www.ruby-forum.com/topic/142809
2
- # Author: Stefan Rusterholz
3
1
  class Hash
2
+
3
+ # From: http://www.ruby-forum.com/topic/142809
4
+ # Author: Stefan Rusterholz
4
5
  def deep_merge(second)
5
6
  merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
6
7
  self.merge(second, &merger)
7
8
  end
8
- end
9
+
10
+ # Make hashes act like ECMAScript objects.
11
+ def method_missing(sym, *args)
12
+ if sym.to_s =~ /(.+)=$/
13
+ self[$1] = args.first
14
+ else
15
+ self[sym] || self[sym.to_s]
16
+ end
17
+ end
18
+
19
+ end
@@ -1,27 +1,91 @@
1
1
  require 'yaml'
2
2
  require 'hash'
3
- require 'settings'
4
-
5
- # Make sure there's a global settings file.
6
- system "touch \"#{ENV['HOME']}/.enzyme.yml\"" unless File.exist?("#{ENV['HOME']}/.enzyme.yml")
7
-
8
- # Default settings.
9
- config = {
10
- :github => {
11
- :user => `git config --global github.user`.rstrip,
12
- :token => `git config --global github.token`.rstrip
13
- }
14
- }
3
+ require 'string'
4
+ require 'errors'
5
+
6
+ # Global formatting helpers.
7
+ $format = {}
8
+ $format.bold = `tput bold`
9
+ $format.normal = `tput sgr0`
10
+
11
+ # System settings.
12
+ $system_settings = {}
13
+ $system_settings.config = {}
14
+ $system_settings.config.global = {}
15
+ $system_settings.config.global.exists = false
16
+ $system_settings.config.global.path = "#{ENV['HOME']}/.enzyme.yml"
17
+ $system_settings.config.organisation = {}
18
+ $system_settings.config.organisation.exists = false
19
+ $system_settings.config.organisation.path = nil
20
+ $system_settings.config.project = {}
21
+ $system_settings.config.project.exists = false
22
+ $system_settings.config.project.path = "./.enzyme.yml"
23
+ $system_settings.sync_server = {}
24
+ $system_settings.sync_server.exists = false
25
+ $system_settings.sync_server.path = nil
26
+ $system_settings.sync_server.skip = !!ARGV.delete('--skip-sync-server')
27
+ $system_settings.trace_errors = !!ARGV.delete('--trace')
28
+ $system_settings.version = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
29
+
30
+ # User configurable settings.
31
+ $settings = {}
32
+ $settings.enzyme_version = nil
33
+ $settings.github = {}
34
+ $settings.github.user = `git config --global github.user`.rstrip
35
+ $settings.github.token = `git config --global github.token`.rstrip
36
+ $settings.project_name = nil
37
+ $settings.projects_directory = nil
38
+ $settings.short_name = nil
39
+ $settings.sync = {}
40
+ $settings.sync.host_name = nil
41
+ $settings.sync.projects_directory = nil
42
+ $settings.sync.share_name = nil
43
+
15
44
  # Global settings.
16
- config = config.deep_merge(YAML.load_file("#{ENV['HOME']}/.enzyme.yml") || {}) if File.exist?("#{ENV['HOME']}/.enzyme.yml")
17
- # Project settings.
18
- config = config.deep_merge(YAML.load_file("./.enzyme.yml") || {}) if File.exist?("./.enzyme.yml")
45
+ system "touch #{$system_settings.config.global.path}" unless File.exist?($system_settings.config.global.path)
46
+ $system_settings.config.global.exists = true
47
+ $settings = $settings.deep_merge(YAML.load_file($system_settings.config.global.path) || {})
48
+
49
+ # Sync server.
50
+ if !$system_settings.sync_server.skip && $settings.sync.host_name && $settings.sync.share_name
19
51
 
20
- # Global settings object.
21
- $settings = Settings.new(config)
52
+ afp_url = "afp://#{$settings.sync.host_name}._afpovertcp._tcp.local/#{$settings.sync.share_name}"
22
53
 
23
- # Global flag for full stacktraces.
24
- $trace_errors = ARGV.delete('--trace')
54
+ # Set the sync server's path.
55
+ $system_settings.sync_server.path = "/Volumes/#{$settings.sync.share_name}"
56
+ # Set the organisation config file's path.
57
+ $system_settings.config.organisation.path = "/Volumes/#{$settings.sync.share_name}/.enzyme.yml"
25
58
 
26
- # Version number.
27
- $version = "0.1.4"
59
+ # Mount the sync server if it isn't already there.
60
+ unless File.directory?($system_settings.sync_server.path)
61
+ `mkdir #{$system_settings.sync_server.path}`
62
+ `mount -t afp #{afp_url} #{$system_settings.sync_server.path} > /dev/null` # > /dev/null is to suppress output
63
+ `rm -r \"/Volumes/#{$settings.sync.share_name}\"` if $? != 0
64
+ end
65
+
66
+ # If the volume has been mounted.
67
+ if File.directory?($system_settings.sync_server.path)
68
+ # Note the sync_server's existence.
69
+ $system_settings.sync_server.exists = true
70
+
71
+ # Organisation settings.
72
+ system "touch #{$system_settings.config.organisation.path}" unless File.exist?($system_settings.config.organisation.path)
73
+ $system_settings.config.organisation.exists = true
74
+ end
75
+
76
+ # Organisation settings.
77
+ if $system_settings.sync_server.exists && $system_settings.config.organisation.exists
78
+ # Merge the organisation settings.
79
+ $settings = $settings.deep_merge(YAML.load_file($system_settings.config.organisation.path) || {})
80
+ # Merge the global settings again (they have a higher priority).
81
+ $settings = $settings.deep_merge(YAML.load_file($system_settings.config.global.path) || {}) if $system_settings.config.global.exists
82
+ end
83
+
84
+ end
85
+
86
+ # Project settings.
87
+ if File.exist?($system_settings.config.project.path)
88
+ # Note the project config file's existence.
89
+ $system_settings.config.project.exists = true
90
+ $settings = $settings.deep_merge(YAML.load_file($system_settings.config.project.path) || {})
91
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def is_i?
3
+ self.to_i.to_s == self.to_s
4
+ end
5
+ end
metadata CHANGED
@@ -1,143 +1,124 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: enzyme
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta01
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Haydn Ewers
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-07 00:00:00 +10:30
19
- default_executable: enzyme
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-05-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2157028440 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- type: :development
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157028440
25
+ - !ruby/object:Gem::Dependency
32
26
  name: shoulda
27
+ requirement: &2156964760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
33
34
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *2156964760
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &2156963220 !ruby/object:Gem::Requirement
37
39
  none: false
38
- requirements:
40
+ requirements:
39
41
  - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 23
42
- segments:
43
- - 1
44
- - 0
45
- - 0
42
+ - !ruby/object:Gem::Version
46
43
  version: 1.0.0
47
44
  type: :development
48
- name: bundler
49
45
  prerelease: false
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- requirement: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *2156963220
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &2156961960 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
51
+ requirements:
55
52
  - - ~>
56
- - !ruby/object:Gem::Version
57
- hash: 7
58
- segments:
59
- - 1
60
- - 5
61
- - 2
53
+ - !ruby/object:Gem::Version
62
54
  version: 1.5.2
63
55
  type: :development
64
- name: jeweler
65
56
  prerelease: false
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: *2156961960
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &2156960780 !ruby/object:Gem::Requirement
69
61
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
77
66
  type: :development
78
- name: rcov
79
67
  prerelease: false
80
- version_requirements: *id004
81
- description: Enzyme is a tool developed by Katalyst to make collaborating on projects easier.
68
+ version_requirements: *2156960780
69
+ description: Enzyme is a tool to make collaborating on projects easier. Developed
70
+ by Katalyst Interactive.
82
71
  email: haydn@katalyst.com.au
83
- executables:
72
+ executables:
84
73
  - enzyme
85
74
  extensions: []
86
-
87
- extra_rdoc_files:
75
+ extra_rdoc_files:
88
76
  - LICENSE.txt
89
- - README.rdoc
90
- files:
77
+ - README.md
78
+ files:
91
79
  - VERSION
92
80
  - bin/enzyme
93
81
  - lib/commands/config.rb
94
82
  - lib/commands/create.rb
95
- - lib/commands/list.rb
83
+ - lib/commands/join.rb
96
84
  - lib/commands/sync.rb
97
- - lib/commands/tasks.rb
98
- - lib/commands/view.rb
99
85
  - lib/enzyme.rb
86
+ - lib/errors.rb
100
87
  - lib/hash.rb
101
- - lib/settings.rb
102
88
  - lib/setup.rb
89
+ - lib/string.rb
103
90
  - LICENSE.txt
104
- - README.rdoc
91
+ - README.md
105
92
  - test/helper.rb
106
93
  - test/test_enzyme.rb
107
- has_rdoc: true
108
94
  homepage: http://github.com/katalyst/enzyme
109
- licenses:
95
+ licenses:
110
96
  - MIT
111
97
  post_install_message:
112
98
  rdoc_options: []
113
-
114
- require_paths:
99
+ require_paths:
115
100
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
101
+ required_ruby_version: !ruby/object:Gem::Requirement
117
102
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ segments:
123
108
  - 0
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
109
+ hash: -2649418028526874740
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
111
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
112
+ requirements:
113
+ - - ! '>'
114
+ - !ruby/object:Gem::Version
115
+ version: 1.3.1
134
116
  requirements: []
135
-
136
117
  rubyforge_project:
137
- rubygems_version: 1.3.7
118
+ rubygems_version: 1.8.6
138
119
  signing_key:
139
120
  specification_version: 3
140
121
  summary: Katalyst's project collaboration tool.
141
- test_files:
122
+ test_files:
142
123
  - test/helper.rb
143
124
  - test/test_enzyme.rb
@@ -1,19 +0,0 @@
1
- = enzyme
2
-
3
- Description goes here.
4
-
5
- == Contributing to enzyme
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
- * Fork the project
10
- * Start a feature/bugfix branch
11
- * Commit and push until you are happy with your contribution
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2011 Haydn Ewers. See LICENSE.txt for
18
- further details.
19
-
@@ -1,7 +0,0 @@
1
- module List extend self
2
-
3
- def run(what=nil)
4
- ARGV.reject { |x| x.start_with?("-") }
5
- end
6
-
7
- end
@@ -1,7 +0,0 @@
1
- module Tasks extend self
2
-
3
- def run(user=nil)
4
- ARGV.reject { |x| x.start_with?("-") }
5
- end
6
-
7
- end
@@ -1,7 +0,0 @@
1
- module View extend self
2
-
3
- def run(what=nil)
4
- ARGV.reject { |x| x.start_with?("-") }
5
- end
6
-
7
- end
@@ -1,44 +0,0 @@
1
- # Based on: http://mjijackson.com/2010/02/flexible-ruby-config-objects
2
- # Authors: Michael Jackson, Haydn Ewers
3
- class Settings
4
-
5
- def initialize(data={})
6
- @data = {}
7
- update!(data)
8
- end
9
-
10
- def update!(data)
11
- data.each do |key, value|
12
- self[key] = value
13
- end
14
- end
15
-
16
- def [](key)
17
- @data[key.to_sym] || @data[key.to_i]
18
- end
19
-
20
- def []=(key, value)
21
- if value.class == Hash
22
- @data[key.to_sym] = Settings.new(value)
23
- else
24
- @data[key.to_sym] = value
25
- end
26
- end
27
-
28
- def to_hash
29
- @data.to_hash
30
- end
31
-
32
- def to_s
33
- @data.to_s
34
- end
35
-
36
- def method_missing(sym, *args)
37
- if sym.to_s =~ /(.+)=$/
38
- self[$1] = args.first
39
- else
40
- self[sym]
41
- end
42
- end
43
-
44
- end