wrkflo 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/wrkflo +59 -0
- data/lib/wrkflo/project.rb +63 -0
- data/lib/wrkflo/step.rb +53 -0
- data/lib/wrkflo/steps/ssh.rb +10 -0
- data/lib/wrkflo/steps/sshfs.rb +13 -0
- data/lib/wrkflo/steps/sublime.rb +9 -0
- data/lib/wrkflo/wrkflo.rb +17 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c9902676f57eb67e87861f6cb79acbc4a1f7472
|
4
|
+
data.tar.gz: f4c48b3d64d32b15256e1ae78f482ac4c9bffdf0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11ad90a2ac574ca8e9cebc40436b52802ccc7fdb43b66dbe9ae38cd5aff50742717f05ad5efb9c4c0d31c4da7edc3bed044ab414e7fe6942786a23822d7a7793
|
7
|
+
data.tar.gz: 014f69b04bdc6e01e240639c94de6397420f5eb21e2aef7b4023c0f1d88cfcbe579a74b9c5844a60a926dbddcb47dd8016d79bf09f0016c8b4b5154e995db6c5
|
data/bin/wrkflo
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'pp'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
require 'wrkflo/wrkflo'
|
8
|
+
|
9
|
+
options = {
|
10
|
+
backward: false,
|
11
|
+
profile: ENV['HOME'] + '/.wrkflorc',
|
12
|
+
project: nil
|
13
|
+
}
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: workon [options] <project>"
|
16
|
+
opts.separator "Start working on things faster with predefined workflows"
|
17
|
+
opts.version = "0.0.2"
|
18
|
+
|
19
|
+
opts.on("-b", "--backward", "Reverse step order and undo compatible steps") do |b|
|
20
|
+
options[:backward] = b
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("-f [FILE]", "--file [FILE]",
|
24
|
+
"The file to interpret as the wrkflo profile.",
|
25
|
+
"Defaults to \"~/.wrkflorc\"") do |file|
|
26
|
+
options[:profile] = file
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
# Parse and remove options from ARGV.
|
31
|
+
opts.parse!
|
32
|
+
rescue OptionParser::ParseError => error
|
33
|
+
# Without this rescue, Ruby would print the stack trace
|
34
|
+
# of the error. Instead, we want to show the error message,
|
35
|
+
# suggest -h or --help, and exit 1.
|
36
|
+
$stderr.puts error
|
37
|
+
$stderr.puts "(-h or --help will show valid options)"
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# An object representation of the entire workon profile, merged with
|
43
|
+
# the options given for this run.
|
44
|
+
workon = WorkOn.new options
|
45
|
+
# The project workflow to execute on this run.
|
46
|
+
project = workon[ARGV[0]]
|
47
|
+
# If no project was specified, notify and exit
|
48
|
+
if project == nil
|
49
|
+
puts "No project specified. Nothing to do."
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
# Run the project workflow in the direction given from the terminal
|
54
|
+
case workon.direction
|
55
|
+
when :forward
|
56
|
+
project.run
|
57
|
+
when :backward
|
58
|
+
project.unrun
|
59
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'wrkflo/step'
|
2
|
+
|
3
|
+
class Project
|
4
|
+
attr_accessor :name, :steps
|
5
|
+
|
6
|
+
def initialize name, steps
|
7
|
+
# The name of this project workflow
|
8
|
+
@name = name
|
9
|
+
# The steps that make up this workflow
|
10
|
+
@steps = steps.map{ |name, config| Step.create(name, config, self) }
|
11
|
+
# The step currently being executed
|
12
|
+
@current_step = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
# Run each step in the order they are specified
|
16
|
+
def run
|
17
|
+
meta_log "Running workflow '#{@name}'"
|
18
|
+
# Reset the current step number
|
19
|
+
@current_step_num = 0
|
20
|
+
# Run the steps
|
21
|
+
@steps.each do |step|
|
22
|
+
# Remember the step being run
|
23
|
+
@current_step = step
|
24
|
+
# Increment the current step so that the first step is 1
|
25
|
+
@current_step_num += 1
|
26
|
+
# Run the step
|
27
|
+
@current_step.run
|
28
|
+
end
|
29
|
+
|
30
|
+
meta_log "Workflow complete"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Undo the steps in reverse order
|
34
|
+
def unrun
|
35
|
+
meta_log "Reversing workflow '#{@name}'"
|
36
|
+
# Reset the current step number
|
37
|
+
@current_step_num = @steps.size
|
38
|
+
# Run the steps
|
39
|
+
@steps.each do |step|
|
40
|
+
# Track the step being run
|
41
|
+
@current_step = step
|
42
|
+
# Run the step
|
43
|
+
@current_step.unrun
|
44
|
+
# Decrement the current step so that the last step is 1
|
45
|
+
@current_step_num -= 1
|
46
|
+
end
|
47
|
+
|
48
|
+
meta_log "Workflow reversed"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Post a message to the terminal with some identifying information
|
52
|
+
def log message
|
53
|
+
puts "> Step ##{@current_step_num} (#{@current_step.name}): #{message}"
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
private
|
58
|
+
# Write a log message with a different prefix marker to visually
|
59
|
+
# indicate a meta-type message
|
60
|
+
def meta_log message
|
61
|
+
puts "- #{message}"
|
62
|
+
end
|
63
|
+
end
|
data/lib/wrkflo/step.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
class Step
|
2
|
+
attr_accessor :name, :config, :project
|
3
|
+
|
4
|
+
# A hash of step aliases to their respective classes. This map determines
|
5
|
+
# the class that a given step in a project will be transformed into.
|
6
|
+
@@step_map = { }
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Add an alias for this class to the step map. Used by subclasses to
|
10
|
+
# register their definitions
|
11
|
+
def add_alias name
|
12
|
+
@@step_map[name.to_sym] = self
|
13
|
+
end
|
14
|
+
|
15
|
+
# Create a new instance of a Step based on the step map entry. If none
|
16
|
+
# exists, a generic Step is created.
|
17
|
+
def create name='', config={}, project=nil
|
18
|
+
@@step_map[name.to_sym].new(name, config, project) or Step.new(name, config, project)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize name, config, project=nil
|
23
|
+
# The name for this step
|
24
|
+
@name = name
|
25
|
+
# The options that define this step
|
26
|
+
@config = config
|
27
|
+
# The project that this step belongs to
|
28
|
+
@project = project
|
29
|
+
end
|
30
|
+
|
31
|
+
# A pass through to this step's project's log. If this step has no project,
|
32
|
+
# a simple puts call is used instead.
|
33
|
+
def log message
|
34
|
+
@project ? @project.log(message) : puts(message)
|
35
|
+
end
|
36
|
+
|
37
|
+
# STEP METHODS
|
38
|
+
#
|
39
|
+
# These methods should be defined by all Step subclasses as given by their
|
40
|
+
# descriptions.
|
41
|
+
|
42
|
+
# The code to run when running this step normally
|
43
|
+
def run
|
44
|
+
log "Nothing to do."
|
45
|
+
end
|
46
|
+
# The code to run when running this step backwards
|
47
|
+
def unrun
|
48
|
+
log "Nothing to do."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Require all step definitions
|
53
|
+
Dir[File.join(__dir__, 'steps', '*')].each{ |step_file| require step_file }
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class SSHStep < Step
|
2
|
+
add_alias :ssh
|
3
|
+
|
4
|
+
def run
|
5
|
+
log "SSHing into #{config['host']} at #{config['directory']}"
|
6
|
+
|
7
|
+
ssh_command = "ssh -t #{config['host']} \\\"#{config['directory']}; bash --login\\\""
|
8
|
+
`osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to set ssh_window to do script "#{ssh_command}"'`
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class SSHFSStep < Step
|
2
|
+
add_alias :sshfs
|
3
|
+
|
4
|
+
def run
|
5
|
+
log "Mounting #{config['host']}:#{config['remote_path']} at #{config['local_path']}"
|
6
|
+
`sshfs #{config['host']}:#{config['remote_path']} #{config['local_path']}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def unrun
|
10
|
+
log "Unmounting #{config['host']}:#{config['remote_path']} from #{config['local_path']}"
|
11
|
+
`umount #{config['local_path']}`
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'wrkflo/project'
|
2
|
+
|
3
|
+
class WorkOn
|
4
|
+
attr_accessor :direction, :profile, :profile_source
|
5
|
+
|
6
|
+
def initialize options
|
7
|
+
@profile = YAML.load(File.open(options[:profile]))
|
8
|
+
@profile_source = options[:profile]
|
9
|
+
@direction = options[:backward] ? :backward : :forward
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get a specific project out of the profile. If the profile does not define
|
13
|
+
# the given project, return nil.
|
14
|
+
def [] project
|
15
|
+
Project.new(project, @profile[project])
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wrkflo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Egeland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: audiobahn404@gmail.com
|
15
|
+
executables:
|
16
|
+
- wrkflo
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/wrkflo
|
21
|
+
- lib/wrkflo/project.rb
|
22
|
+
- lib/wrkflo/step.rb
|
23
|
+
- lib/wrkflo/steps/ssh.rb
|
24
|
+
- lib/wrkflo/steps/sshfs.rb
|
25
|
+
- lib/wrkflo/steps/sublime.rb
|
26
|
+
- lib/wrkflo/wrkflo.rb
|
27
|
+
homepage: http://github.com/audiobahn404/wrkflo
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.2.0
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.4.7
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Get working on things faster with predefined wrkflos.
|
51
|
+
test_files: []
|