my_scripts 0.0.24 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +9 -6
- data/README.rdoc +44 -31
- data/VERSION +1 -1
- data/bin/{dummy → bon} +1 -1
- data/lib/my_scripts/script.rb +10 -2
- data/lib/my_scripts/scripts/bon.rb +21 -0
- data/lib/my_scripts/{citi.rb → scripts/citi.rb} +0 -0
- data/lib/my_scripts/{gitto.rb → scripts/gitto.rb} +1 -1
- data/lib/my_scripts/{jew.rb → scripts/jew.rb} +0 -0
- data/lib/my_scripts/{rabbit.rb → scripts/rabbit.rb} +3 -2
- data/lib/my_scripts/{wake.rb → scripts/wake.rb} +0 -0
- metadata +10 -10
- data/lib/my_scripts/dummy.rb +0 -17
data/HISTORY
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
==
|
2
|
-
|
3
|
-
* 1 major enhancement
|
4
|
-
* Birthday!
|
1
|
+
== 0.0.0 / 2010-04-08
|
2
|
+
|
3
|
+
* 1 major enhancement
|
4
|
+
* Birthday!
|
5
5
|
|
6
6
|
== 0.0.22 / 2010-04-12
|
7
7
|
|
8
|
-
== 0.0.
|
8
|
+
== 0.0.27 / 2010-04-13
|
9
|
+
|
10
|
+
== 0.1.0 / 2010-04-13
|
9
11
|
|
10
|
-
|
12
|
+
* Bones dependency eliminated
|
13
|
+
* Codebase cleaned up
|
data/README.rdoc
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
== my_scripts
|
2
|
+
by: Arvicco
|
3
|
+
url: http://github.com/arvicco/my_scripts
|
4
4
|
|
5
|
-
|
5
|
+
=== DESCRIPTION:
|
6
6
|
|
7
7
|
A collection of simple scripts/commands used to save time and avoid memorizing/
|
8
8
|
retyping chains of boilerplate console commands and their arguments. Packaged
|
@@ -10,7 +10,7 @@ as a gem to make it easily available everywhere without the need to set up
|
|
10
10
|
paths, environments and all such nonsense... It is also not OS-specific, so
|
11
11
|
(in theory) scripts should work on Mac, *nix and Windows.
|
12
12
|
|
13
|
-
|
13
|
+
=== FEATURES:
|
14
14
|
|
15
15
|
OK, I confess: I wanted to write scripts but had neither time nor desire to learn
|
16
16
|
all the esoterics of bash, cmd/powershell and mac scripting. So, I set out to do
|
@@ -18,30 +18,44 @@ all my scripting in Ruby. I also wanted my scripts to be easily testable, that's
|
|
18
18
|
why I created a simple scripting framework instead of stuffing each script into a
|
19
19
|
separate executable Ruby file as most people do.
|
20
20
|
|
21
|
+
Yes, I know about Rake tasks - however they are tied to specific directory and
|
22
|
+
notoriously difficult to test/debug. I also learned about Thor, which may be a good
|
23
|
+
fit for most things I need to do - but prefixing every command with 'thor' kinda
|
24
|
+
puts me off. Besides, I wanted to have something dead simple and entirely under
|
25
|
+
my control, rather than depending on 3rd party magic.
|
26
|
+
|
21
27
|
These scripts are very much targeted to my own specific needs, but if you find them
|
22
28
|
useful or need additional features, I'll be happy to generalize. You can also use this
|
23
29
|
gem as a basis for writing your own simple scripts that are easy to test and maintain.
|
24
30
|
|
31
|
+
My scripts do not have lots of moving parts:
|
32
|
+
* MyScripts::CLI provides context for running scripts (like telling them where stdin and stdout are)
|
33
|
+
* MyScripts::Script is a template class defining all the basic methods
|
34
|
+
* MyScripts::YourOwnScript is your script proper. Make it a subclass of MyScripts::Script and
|
35
|
+
define method 'run' - that's all there is to it
|
36
|
+
* Executable file in bin that calls MyScripts::CLI.run with arguments being your script name and ARGV
|
37
|
+
|
38
|
+
=== PROBLEMS:
|
39
|
+
|
25
40
|
Ah, yes - this gem will work only with Ruby 1.9 and later. I use advanced string encoding
|
26
41
|
features in my scripts, so 1.8 is not an option for me, and providing backward compatibility
|
27
42
|
looks like too much pain. Ruby 1.9 is the way of the future, so let's move forward!
|
28
43
|
|
29
|
-
|
44
|
+
=== INSTALL:
|
30
45
|
|
31
46
|
$ sudo gem install my_scripts
|
32
47
|
|
33
|
-
|
34
|
-
|
48
|
+
=== SYNOPSIS:
|
49
|
+
==== Creating your own scripts
|
35
50
|
|
36
51
|
First, you need to either fork my_scripts on github or clone it to your computer with:
|
37
52
|
|
38
53
|
$ git clone git://github.com/arvicco/my_scripts.git
|
39
54
|
|
40
|
-
Now, put your Ruby file inside lib/my_scripts. It will be auto-loaded. Use MyScripts
|
41
|
-
module as a
|
42
|
-
actual work:
|
55
|
+
Now, put your Ruby file inside lib/my_scripts/scripts. It will be auto-loaded. Use MyScripts
|
56
|
+
module as a namespace, subclass Script and redefine run method to do all the actual work:
|
43
57
|
|
44
|
-
#-------- lib/my_scripts/my_shiny_script.rb----------
|
58
|
+
#-------- lib/my_scripts/scripts/my_shiny_script.rb----------
|
45
59
|
module MyScripts
|
46
60
|
class MyShinyScript < Script
|
47
61
|
def run
|
@@ -64,35 +78,34 @@ Put your executable into bin directory, with something like this:
|
|
64
78
|
MyScripts::CLI.run :my_shiny_script, ARGV
|
65
79
|
#-------
|
66
80
|
|
67
|
-
|
68
|
-
|
69
|
-
OK, so you're not advanced enough to follow even these simple instructions. No problemo.
|
70
|
-
I guess you still managed to install my_scripts gem if you are reading this, so just modify it.
|
71
|
-
Locate my_scripts gem in gem directory (usually it's something like ../ruby/lib/ruby/gems/1.9.1/gems).
|
72
|
-
I have dummy script skeleton in lib/my_scripts/dummy.rb that is ready for your use. Just put your
|
73
|
-
script code inside run method (if you use ARGV, change it to @argv). Done! You can
|
74
|
-
immediately run your script anywhere in the system using the following command:
|
75
|
-
|
76
|
-
$ dummy Whatever arguments your code expects and processes
|
77
|
-
|
78
|
-
=== Using existing scripts
|
81
|
+
==== Using existing scripts
|
79
82
|
|
80
83
|
$ jew project_name Summary or description goes here
|
81
84
|
|
82
85
|
This script uses Jeweler to create new project skeleton, local git repo and
|
83
|
-
initiate remote repo on
|
86
|
+
initiate remote repo on Github. No need to enclose your description in quotes.
|
87
|
+
|
88
|
+
$ bon project_name Summary or description goes here
|
89
|
+
|
90
|
+
This script uses Mr.Bones to create new project skeleton, local git repo and
|
91
|
+
initiate remote repo on Github. No need to enclose your description in quotes.
|
84
92
|
|
85
|
-
$ gitto [
|
93
|
+
$ gitto [VERSION] Commit message goes here
|
86
94
|
|
87
95
|
Save the result of all your project-related work with one command. It adds all
|
88
96
|
new files to git VCS, commits all changes with a timestamped message, opionally
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
97
|
+
changes version and pushes to git remote(s).
|
98
|
+
First arg is considered a version command if it is like this:
|
99
|
+
1.2.3 - Explicit version set,
|
100
|
+
1 - Version bump:patch,
|
101
|
+
10 - Version bump:minor,
|
102
|
+
100 - Version bump:major,
|
103
|
+
.patch - Adding patch.
|
104
|
+
Otherwise all arguments are treated as part of commit message. Use this command inside
|
105
|
+
project directory, preferably at top level.
|
93
106
|
|
94
107
|
...
|
95
108
|
|
96
|
-
|
109
|
+
=== LICENSE:
|
97
110
|
|
98
111
|
Copyright (c) 2009 Arvicco. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/{dummy → bon}
RENAMED
data/lib/my_scripts/script.rb
CHANGED
@@ -16,10 +16,11 @@ module MyScripts
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# This is where all action happens. Should be defined by all Script implementations
|
19
20
|
def run
|
20
21
|
end
|
21
22
|
|
22
|
-
def puts *args
|
23
|
+
def puts( *args )
|
23
24
|
@cli.stdout.puts *args
|
24
25
|
nil
|
25
26
|
end
|
@@ -28,13 +29,20 @@ module MyScripts
|
|
28
29
|
@cli.stdin.gets
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
+
# Outputs usage notes (and optional extended explanation), then exits with code 1
|
33
|
+
def usage( examples, explanation = nil )
|
32
34
|
puts "Script #{@name} #{version} - Usage:"
|
33
35
|
(examples.respond_to?(:split) ? examples.split("\n") : examples).map {|line| puts " #{@name} #{line}"}
|
34
36
|
puts explanation if explanation
|
35
37
|
exit 1
|
36
38
|
end
|
37
39
|
|
40
|
+
# Outputs error text, then exits with code 1
|
41
|
+
def error( text )
|
42
|
+
puts "Script #{@name} #{version} - Error: #{text}"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
38
46
|
def to_s
|
39
47
|
"#{@name} #{@argv.join(' ')} -> #{self.class}"
|
40
48
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MyScripts
|
2
|
+
# This script uses Mr.Bones gem to create new project skeleton, local git repo and
|
3
|
+
# initiate remote repo on github
|
4
|
+
#
|
5
|
+
class Bon < Script
|
6
|
+
DEFAULT_SKELETON = 'basic'
|
7
|
+
def run
|
8
|
+
usage "name Summary or description goes here" if @argv.empty?
|
9
|
+
|
10
|
+
# First Arg should be project name
|
11
|
+
name = @argv.shift
|
12
|
+
|
13
|
+
# All the other args lumped into summary, or default summary
|
14
|
+
summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
|
15
|
+
|
16
|
+
puts "Creating Bones project #{name} with summary: #{summary}"
|
17
|
+
|
18
|
+
system %Q[bones create --github "#{summary}" -s #{DEFAULT_SKELETON} #{name}]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
@@ -8,7 +8,7 @@ module MyScripts
|
|
8
8
|
usage "[0.1.2 - version, 100/10/1 - bump major/minor/patch, .patch - add patch] Commit message goes here" if @argv.empty?
|
9
9
|
|
10
10
|
# First Arg may indicate version command if it matches pattern
|
11
|
-
ver = @argv[0] =~ /^(\d+\.\d+\.\d+(?:\.(.*?))?|\.(.*?)|\d{1}0{0,2})$/ ? @argv
|
11
|
+
ver = @argv[0] =~ /^(\d+\.\d+\.\d+(?:\.(.*?))?|\.(.*?)|\d{1}0{0,2})$/ ? @argv.shift : nil
|
12
12
|
|
13
13
|
# All the other args lumped into message, or default message
|
14
14
|
message = @argv.empty? ? "Commit #{Time.now.to_s[0..-6]}" : @argv.join(' ')
|
File without changes
|
@@ -2,8 +2,9 @@ module MyScripts
|
|
2
2
|
# Starts and controls rabbitmq server
|
3
3
|
class Rabbit < Script
|
4
4
|
def run
|
5
|
+
error 'ERLANG_HOME not set' unless ENV['ERLANG_HOME']
|
5
6
|
rabbit_hole = ENV['ERLANG_HOME'] + '/lib/rabbitmq_server-1.7.0/sbin'
|
6
|
-
case @argv.shift
|
7
|
+
case @argv.shift
|
7
8
|
when /start/
|
8
9
|
system "#{rabbit_hole}/rabbitmq-server.bat #{@argv.join(' ')}"
|
9
10
|
when /stop/
|
@@ -12,7 +13,7 @@ module MyScripts
|
|
12
13
|
system "#{rabbit_hole}/rabbitmqctl.bat #{@argv.join(' ')}"
|
13
14
|
else
|
14
15
|
usage ["start [args] - starts rabbitmq node", "stop [args] - stops running rabbitmq node",
|
15
|
-
"ctl [args] - controls rabbitmq node"]
|
16
|
+
"ctl [args] - controls rabbitmq node"], explanation
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
File without changes
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.24
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- arvicco
|
@@ -46,8 +46,8 @@ dependencies:
|
|
46
46
|
description: Describe package my_scripts
|
47
47
|
email: arvitallian@gmail.com
|
48
48
|
executables:
|
49
|
+
- bon
|
49
50
|
- citi
|
50
|
-
- dummy
|
51
51
|
- gitto
|
52
52
|
- jew
|
53
53
|
- rabbit
|
@@ -59,21 +59,21 @@ extra_rdoc_files:
|
|
59
59
|
- HISTORY
|
60
60
|
- README.rdoc
|
61
61
|
files:
|
62
|
+
- bin/bon
|
62
63
|
- bin/citi
|
63
|
-
- bin/dummy
|
64
64
|
- bin/gitto
|
65
65
|
- bin/jew
|
66
66
|
- bin/rabbit
|
67
67
|
- bin/wake
|
68
|
-
- lib/my_scripts/citi.rb
|
69
68
|
- lib/my_scripts/cli.rb
|
70
|
-
- lib/my_scripts/dummy.rb
|
71
69
|
- lib/my_scripts/extensions.rb
|
72
|
-
- lib/my_scripts/gitto.rb
|
73
|
-
- lib/my_scripts/jew.rb
|
74
|
-
- lib/my_scripts/rabbit.rb
|
75
70
|
- lib/my_scripts/script.rb
|
76
|
-
- lib/my_scripts/
|
71
|
+
- lib/my_scripts/scripts/bon.rb
|
72
|
+
- lib/my_scripts/scripts/citi.rb
|
73
|
+
- lib/my_scripts/scripts/gitto.rb
|
74
|
+
- lib/my_scripts/scripts/jew.rb
|
75
|
+
- lib/my_scripts/scripts/rabbit.rb
|
76
|
+
- lib/my_scripts/scripts/wake.rb
|
77
77
|
- lib/my_scripts.rb
|
78
78
|
- spec/my_scripts/extensions_spec.rb
|
79
79
|
- spec/my_scripts_spec.rb
|
data/lib/my_scripts/dummy.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# Dummy script skeleton that is ready for your usage. Just put your script code
|
3
|
-
# inside run method (if you use ARGV, change it to @argv). Done!
|
4
|
-
# You can immediately run your script anywhere using following command:
|
5
|
-
# $ dummy Whatever arguments your code expects and processes
|
6
|
-
#
|
7
|
-
class Dummy < Script
|
8
|
-
def run
|
9
|
-
# here you do all actual work for your script
|
10
|
-
# you have following instance vars at your disposal:
|
11
|
-
# @name - your script name,
|
12
|
-
# @argv - your ARGV (Array of argument Strings passed at command line),
|
13
|
-
# @cli - CLI runner (holds references to stdin and stdout)
|
14
|
-
#...
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|