runfile 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e1e4b811b20fb3a6a072a25ad05c6cabada1191
4
- data.tar.gz: 225f4622994b215a2f8528608e8979efca08da0d
3
+ metadata.gz: 45bf6efe3fbf5afdb2e64292cab5ec675ff1930b
4
+ data.tar.gz: 304c5f384ec15e0311654b8cd8e383442c2132fc
5
5
  SHA512:
6
- metadata.gz: 80d1173e587d084821f875e2c2ce7e2b530503d8dd01909b5516cb7adfe28acc7d8eaf379fdf0bd0409b53c09835bedc130dbdcbe0da7344ad0d584d7a4eb98f
7
- data.tar.gz: ebac3b2ea0e53e8f7f39ac6d32c874a5617d4bb66169a4f4912d9b79ab79121b73ab6af69f0643eda467f6efcc205e83433d11581e9e731271ccf8ec63d98762
6
+ metadata.gz: bdc1b161acd30d43cb447fdb06bb6e9ccaf0214389daac3469169a1d1fb5961ad8c96e2ab75a862d6e4d8bce8457d7c894ee25bbbdb4f2289d8886a2cd20e794
7
+ data.tar.gz: 653e5140d60b20fac61eec1747dadc1ba4e9823fe36222d104c41bc0760f3431c3ebf1a0d326c94ced91f6868a828247764310c424601ff783111e226c31b763
data/README.md CHANGED
@@ -21,6 +21,8 @@ to [Rake](https://github.com/ruby/rake), but with the full power of
21
21
  You create a `Runfile`, and execute commands with
22
22
  `run command arguments -and --flags`.
23
23
 
24
+ ![Runfile Demo](https://raw.githubusercontent.com/DannyBen/runfile/dev/demo.gif "Runfile Demo")
25
+
24
26
  [Learn More in the Wiki](https://github.com/DannyBen/runfile/wiki)
25
27
 
26
28
  ---
@@ -1,10 +1,10 @@
1
1
  require 'runfile/version'
2
2
  require 'runfile/settings'
3
+ require 'runfile/setup'
3
4
  require 'runfile/docopt_helper'
4
5
  require 'runfile/runfile_helper'
5
6
  require 'runfile/action'
6
7
  require 'runfile/runner'
7
8
  require 'runfile/dsl'
8
- require 'runfile/util'
9
-
10
- require 'runfile/extensions/exec'
9
+ require 'runfile/exec'
10
+ require 'runfile/deprecations'
@@ -0,0 +1,14 @@
1
+ module Runfile
2
+
3
+ # The Runfile::Exec module is derecated. It is kept here so that those
4
+ # who include it in the past will know what to do.
5
+ module Exec
6
+ def self.included(base)
7
+ say! "!txtred!Runfile::Exec is deprecated. You should change your Runfile:"
8
+ say! "!txtred! 1. There is no need to include Runfile::Exec, it is already included."
9
+ say! "!txtred! 2. Change any configuration from Runfile::Exec.pid_dir to Runfile.pid_dir"
10
+ abort
11
+ end
12
+ end
13
+
14
+ end
@@ -2,59 +2,117 @@
2
2
  # All commands are immediately handed over to the Runner instance
3
3
  # for handling.
4
4
 
5
- # Smells of :reek:UtilityFunction
6
5
  module Runfile
7
6
  # Set the name of your Runfile program
7
+ # name 'My Runfile'
8
8
  def name(name)
9
9
  Runner.instance.name = name
10
10
  end
11
11
 
12
12
  # Set the version of your Runfile program
13
+ # version '0.1.0'
13
14
  def version(ver)
14
15
  Runner.instance.version = ver
15
16
  end
16
17
 
17
18
  # Set the one line summary of your Runfile program
19
+ # summary 'Utilities for my server'
18
20
  def summary(text)
19
21
  Runner.instance.summary = text
20
22
  end
21
23
 
22
24
  # Set the usage pattern for the next action
25
+ # usage 'server [--background]'
23
26
  def usage(text)
24
27
  Runner.instance.last_usage = text
25
28
  end
26
29
 
27
30
  # Set the help message for the next action
31
+ # help 'Starts the server in the foreground or background'
28
32
  def help(text)
29
33
  Runner.instance.last_help = text
30
34
  end
31
35
 
32
36
  # Add an option/flag to the next action (can be called multiple
33
37
  # times)
38
+ # option '-b --background', 'Start in the background'
34
39
  def option(flag, text, scope=nil)
35
40
  Runner.instance.add_option flag, text, scope
36
41
  end
37
42
 
38
43
  # Set an example command (can be called multiple times)
44
+ # example 'server --background'
39
45
  def example(text)
40
46
  Runner.instance.add_example text
41
47
  end
42
48
 
43
49
  # Define the action
50
+ # action :server do |args|
51
+ # run 'rails server'
52
+ # end
44
53
  def action(name, altname=nil, &block)
45
54
  Runner.instance.add_action name, altname, &block
46
55
  end
47
56
 
48
57
  # Define a new command namespace
58
+ # command 'server'
59
+ # # ... define actions here
60
+ # endcommand
49
61
  def command(name=nil)
50
62
  Runner.instance.namespace = name
51
63
  end
52
64
 
53
65
  # Cross-call another action
66
+ # call 'other_action'
54
67
  def call(command_string)
55
68
  Runner.instance.cross_call command_string
56
69
  end
57
70
 
71
+ # Run a command, wait until it is done and continue
72
+ # run 'rails server'
73
+ def run(*args)
74
+ ExecHandler.instance.run *args
75
+ end
76
+
77
+ # Run a command, wait until it is done, then exit
78
+ # run! 'rails server'
79
+ def run!(*args)
80
+ ExecHandler.instance.run! *args
81
+ end
82
+
83
+ # Run a command in the background, optionally log to a log file and save
84
+ # the process ID in a pid file
85
+ # run_bg 'rails server', pid: 'rails', log: 'tmp/log.log'
86
+ def run_bg(*args)
87
+ ExecHandler.instance.run_bg *args
88
+ end
89
+
90
+ # Stop a command started with 'run_bg'. Provide the name of he pid file you
91
+ # used in 'run_bg'
92
+ # stop_bg 'rails'
93
+ def stop_bg(*args)
94
+ ExecHandler.instance.stop_bg *args
95
+ end
96
+
97
+ # Set a block to be called before each run. The block should return
98
+ # the command to run, since this is intended to let the block modify
99
+ # the command if it needs to.
100
+ # before_run do |command|
101
+ # puts "BEFORE #{command}"
102
+ # command
103
+ # end
104
+ def before_run(&block)
105
+ ExecHandler.instance.before_run &block
106
+ end
107
+
108
+ # Set a block to be called after each run
109
+ # before_run do |command|
110
+ # puts "AFTER #{command}"
111
+ # end
112
+ def after_run(&block)
113
+ ExecHandler.instance.after_run &block
114
+ end
115
+
58
116
  # Also allow to use 'endcommand' instead of 'command' to end
59
117
  # a command namespace definition
60
118
  alias_method :endcommand, :command
@@ -1,23 +1,19 @@
1
- # This module provides methods for easily and politely run shell commands
2
- # through a Runfile action.
3
- # It is mainly a convenient wrapper around `system` and `exec` and it also
4
- # adds functions for running background tasks with ease.
1
+ require 'singleton'
5
2
 
6
3
  module Runfile
7
- module Exec
8
- def self.pid_dir=(dir)
9
- @@pid_dir = dir
10
- end
11
4
 
12
- def self.pid_dir
13
- @@pid_dir
14
- end
5
+ # This class provides methods for easily and politely run shell commands
6
+ # through a Runfile action.
7
+ # It is mainly a convenient wrapper around `system` and `exec` and it also
8
+ # adds functions for running background tasks with ease.
9
+ class ExecHandler
10
+ include Singleton
15
11
 
16
12
  # Run a command, wait until it is done and continue
17
13
  def run(cmd)
18
14
  cmd = @before_run_block.call(cmd) if @before_run_block
19
15
  return false unless cmd
20
- say "!txtgrn!> #{cmd}"
16
+ say "!txtgrn!> #{cmd}" unless Runfile.quiet
21
17
  system cmd
22
18
  @after_run_block.call(cmd) if @after_run_block
23
19
  end
@@ -26,7 +22,7 @@ module Runfile
26
22
  def run!(cmd)
27
23
  cmd = @before_run_block.call(cmd) if @before_run_block
28
24
  return false unless cmd
29
- say "!txtgrn!> #{cmd}"
25
+ say "!txtgrn!> #{cmd}" unless Runfile.quiet
30
26
  exec cmd
31
27
  end
32
28
 
@@ -36,7 +32,7 @@ module Runfile
36
32
  cmd = @before_run_block.call(cmd) if @before_run_block
37
33
  return false unless cmd
38
34
  full_cmd = "exec #{cmd} >#{log} 2>&1"
39
- say "!txtgrn!> #{full_cmd}"
35
+ say "!txtgrn!> #{full_cmd}" unless Runfile.quiet
40
36
  process = IO.popen "exec #{cmd} >#{log} 2>&1"
41
37
  File.write pidfile(pid), process.pid if pid
42
38
  @after_run_block.call(cmd) if @after_run_block
@@ -52,7 +48,7 @@ module Runfile
52
48
  File.delete file
53
49
  run "kill -s TERM #{pid}"
54
50
  else
55
- say "!txtred!PID file not found."
51
+ say "!txtred!PID file not found." unless Runfile.quiet
56
52
  end
57
53
  end
58
54
 
@@ -69,7 +65,7 @@ module Runfile
69
65
  private
70
66
 
71
67
  def pid_dir
72
- defined?(@@pid_dir) ? @@pid_dir : nil
68
+ defined?(Runfile.pid_dir) ? Runfile.pid_dir : nil
73
69
  end
74
70
 
75
71
  def pidfile(pid)
@@ -77,5 +73,4 @@ module Runfile
77
73
  end
78
74
 
79
75
  end
80
-
81
- end
76
+ end
@@ -123,18 +123,16 @@ module Runfile
123
123
 
124
124
  # Output the list of available runfiles without filename
125
125
  def say_runfile_usage(runfiles)
126
- namelist = runfiles.map {|f| /([^\/]+).runfile$/.match(f)[1] }
127
- width = detect_terminal_size[0]
128
- max = namelist.max_by(&:length).length
129
- message = " " + namelist.map {|f| f.ljust max+1 }.join(' ')
126
+ runfiles_as_columns = get_runfiles_as_columns runfiles
130
127
 
131
128
  say "#{settings.intro}\n" if settings.intro
132
129
  say "Usage: run <file>"
133
- say word_wrap(message, width)
130
+ say runfiles_as_columns
134
131
 
135
132
  show_shortcuts if settings.shortcuts
136
133
  end
137
134
 
135
+ # Prints a friendly output of the shortcut list
138
136
  def show_shortcuts
139
137
  say "\nShortcuts:"
140
138
  max = settings.shortcuts.keys.max_by(&:length).length
@@ -143,5 +141,24 @@ module Runfile
143
141
  end
144
142
  end
145
143
 
144
+ # Returns the list of runfiles, organized as columns based on the
145
+ # current terminal width
146
+ def get_runfiles_as_columns(runfiles)
147
+ namelist = runfile_names runfiles
148
+ width = detect_terminal_size[0]
149
+ max = namelist.max_by(&:length).length
150
+ message = " " + namelist.map {|f| f.ljust max+1 }.join(' ')
151
+ word_wrap message, width
152
+ end
153
+
154
+ def runfile_names(runfiles)
155
+ runfiles.map {|f| /([^\/]+).runfile$/.match(f)[1] }.sort
156
+ end
157
+
158
+ # Returns an array of path directories
159
+ def path_dirs
160
+ ENV['PATH'].split(File::PATH_SEPARATOR)
161
+ end
162
+
146
163
  end
147
164
  end
@@ -0,0 +1,19 @@
1
+ module Runfile
2
+ class << self
3
+ # Set the directory where PID files are stored when using `run_bg`
4
+ # Runfile.pid_dir = 'tmp'
5
+ attr_accessor :pid_dir
6
+
7
+ # Disable echoing of the command when using `run` or `run!`
8
+ # Runfile.quiet = true
9
+ attr_accessor :quiet
10
+
11
+ # You can also configure Runfile by providing a block:
12
+ # Runfile.setup do |config|
13
+ # config.quiet = true
14
+ # end
15
+ def setup
16
+ yield self
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
11
+ date: 2016-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -122,14 +122,15 @@ files:
122
122
  - bin/run!
123
123
  - lib/runfile.rb
124
124
  - lib/runfile/action.rb
125
+ - lib/runfile/deprecations.rb
125
126
  - lib/runfile/docopt_helper.rb
126
127
  - lib/runfile/dsl.rb
127
- - lib/runfile/extensions/exec.rb
128
+ - lib/runfile/exec.rb
128
129
  - lib/runfile/runfile_helper.rb
129
130
  - lib/runfile/runner.rb
130
131
  - lib/runfile/settings.rb
132
+ - lib/runfile/setup.rb
131
133
  - lib/runfile/templates/Runfile
132
- - lib/runfile/util.rb
133
134
  - lib/runfile/version.rb
134
135
  homepage: https://github.com/DannyBen/runfile
135
136
  licenses:
@@ -1,15 +0,0 @@
1
- # Utility methods
2
- module Runfile
3
- # Debug print and exit
4
- # Smells of :reek:UncommunicativeMethodName
5
- def d(obj)
6
- pp obj
7
- exit
8
- end
9
-
10
- # Return an array of path directories
11
- # Smells of :reek:UtilityFunction
12
- def path_dirs
13
- ENV['PATH'].split(File::PATH_SEPARATOR)
14
- end
15
- end