elscripto 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ elscripto is a command line automator. It was initially written to start up a fe
4
4
 
5
5
  ## Platforms
6
6
 
7
- This gem currently works on Mac OSX, and Linux with Gnome or KDE desktops.
7
+ This gem currently works on Mac OSX and Linux with Gnome or KDE desktops.
8
8
  It uses Applescript, gnome-terminal and konsole automation via qdbus depending on the platform.
9
9
 
10
10
  ## Installation
@@ -23,34 +23,55 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- From within a project directory, run the following command to bootstrap Elscripto.
26
+ As of version 0.6.0 there are a few different ways of using elscripto.
27
+
28
+
29
+ ### Supply commands from the command line:
30
+ You can simply use the `-c (--commands)` argument to pass an array or shell commands directly:
31
+
32
+ $ elscripto start -c 'ssh server1; ssh server2;ssh server3'
33
+
34
+ Elscripto will run each command in a different tab.
35
+
36
+ ### Use a configuration file:
37
+ Run the following command to bootstrap a configuration file in the current directory:
27
38
 
28
39
  $ elscripto init
29
40
 
30
41
  This will create an `.elscripto` file, containing a few command definitions that you can edit to your liking.
31
42
  From then on, every time you call `elscripto` from within that folder, the specified commands will be ran in different tabs. [This is an example configuration](https://github.com/Achillefs/elscripto/blob/master/config/elscripto.init.yml) file that also tells you how to add your own definitions in a project.
32
43
 
33
- ### Command Definitions
44
+ If the default configuration file path doesn't suit your needs, you can always call `elscripto` with the -f (or --file) option, pointing to your custom configuration file.
45
+
46
+ Example:
47
+
48
+ $ elscripto start -f /path/to/my/conf.yml
34
49
 
50
+ ### Supply command definitions from the command line:
51
+ Finally, you can call `elscripto` with the `-d (--definitions)` argument:
52
+
53
+ $ elscripto start -d 'rails:server;rails:watchr;spork;custom_command'
54
+
55
+ This command goes through your system's configuration files (see [Command Definitions](#command-definitions)) and expands the definitions you provided. This allows you to create your own commands just the way you like 'em, and easily call them from anywhere in the system.
56
+
57
+ ## Command Definitions
35
58
  Elscripto comes with a few built-in shell commands; Upon first run, a default configuration file is installed in a platform-dependent directory
36
59
 
37
- * **OSX**: `/usr/local/etc/elscripto/_default.conf`
38
- * **Linux**: `<your home dir>/.config/elscripto/_default.conf`
60
+ * **OSX**: `/usr/local/etc/elscripto/_default.conf`
61
+ * **Linux**: `<your home dir>/.config/elscripto/_default.conf`
39
62
 
40
63
  Have a look at the bundled [elscripto.conf.yml](https://github.com/Achillefs/elscripto/blob/master/config/elscripto.conf.yml) for a list of built-in commands.
41
64
 
42
65
  You can drop in more files in there and as long as the file extension is conf, Elscripto will attempt to load the definitions. Bear in mind the following:
43
66
 
44
- * Definition files are loaded alphabetically, so you can overwrite a default definition (or one of yours for that matter) by re-defining it in a latter custom configuration file
45
- * Overwriting `default.conf` is not a good idea, your changes are probably gonna get overwritten by a gem update
67
+ * Definition files are loaded alphabetically, so you can overwrite a default definition (or one of yours for that matter) by re-defining it in a latter custom configuration file
68
+ * Overwriting `default.conf` is not a good idea, your changes are probably gonna get overwritten by a gem update
46
69
 
47
70
  ## Suggestions, comments, bugs, whatever
48
-
49
71
  Feel free to use Issues to submit bugs, suggestions or feature requests.
50
72
  Elscripto should work on all major platforms (yes, even Windows), let not my limited knowledge / experience and time stand in the way!
51
73
 
52
74
  ## Contributing
53
-
54
75
  1. Fork it
55
76
  2. Create your feature branch (`git checkout -b my-new-feature`)
56
77
  3. Commit your changes (`git commit -am 'Add some feature'`)
@@ -58,9 +79,9 @@ Elscripto should work on all major platforms (yes, even Windows), let not my lim
58
79
  5. Create new Pull Request
59
80
 
60
81
  ## Changelog
61
-
62
- * 0.5.0 KDE support
63
- * 0.4.0 Custom configuration files support
64
- * 0.3.0 GNOME support
65
- * 0.2.0 OSX support
66
- * 0.1.0 Initial release
82
+ * 0.6.0 Added `--definitions`, `--commands` and `--file` cli arguments
83
+ * 0.5.0 KDE support
84
+ * 0.4.0 Custom configuration files support
85
+ * 0.3.0 GNOME support
86
+ * 0.2.0 OSX support
87
+ * 0.1.0 Initial release
@@ -1,44 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'elscripto'
4
+ require 'optparse'
4
5
  require 'nutrun-string'
5
6
 
6
- def run(command)
7
- executable_name = File.basename($PROGRAM_NAME)
8
-
9
- if command != nil and %{init start --version}.include?(command) # valid command?
10
- case command
11
- when 'init'
12
- print "\nInitializing elscripto...".yellow
13
- begin
14
- Elscripto::App.init!
15
- puts " done."
16
- puts "Before continuing, update ./.elscripto with the desired script definitions\n\n".yellow
17
- rescue Elscripto::AlreadyInitializedError
18
- puts " nah, it's already there!\n".green
19
- end
20
- when 'start'
21
- if File.exists? Elscripto::App::CONFIG_FILE
22
- begin
23
- app = Elscripto::App.new(Elscripto::App::CONFIG_FILE)
24
- puts 'Starting ElScripto Spctacularrr!'.green
25
- app.exec!
26
- rescue Elscripto::NoDefinitionsError,Elscripto::UnsupportedOSError,Elscripto::LaunchFailedError => e
27
- puts "\n#{e.message}\n".red
28
- end
29
- else
30
- print "No configuration found, initializing...".yellow
31
- Elscripto::App.init!
32
- puts "done.".green
33
- puts "Before continuing, update ./.elscripto with the desired script definitions".yellow
34
- end
35
- when '--version', '-v'
36
- puts "\n#{executable_name.capitalize} version #{Elscripto::VERSION}".white
37
- puts "(c) 2012, Achillefs Charmpilas\n".green
38
- end
39
- else # valid command?
40
- puts "\nUsage: #{executable_name} init|start\n".white
41
- end # valid command?
42
- end
43
-
44
- run(ARGV[0]) unless ENV['NO_RUN']
7
+ begin
8
+ command = Elscripto::Options::VALID_COMMANDS.include?(ARGV[0]) ? ARGV[0] : ''
9
+ options = Elscripto::Options.parse command, ARGV
10
+ app = Elscripto::App.new(options)
11
+ app.exec!
12
+ rescue Elscripto::InvalidCommandError,
13
+ Elscripto::NoDefinitionsError, Elscripto::UnsupportedOSError,
14
+ Elscripto::AlreadyInitializedError, Elscripto::LaunchFailedError => e
15
+ puts "\nElscripto error: #{e.message}\n".red
16
+ puts e.backtrace.join("\n") if options.enviroment == :development
17
+ end
@@ -7,4 +7,7 @@
7
7
  rails:logtail: 'rake log:clear && tail -f log/development.log'
8
8
  rails:compass: 'compass watch'
9
9
  rails:watchr: 'watchr ./config/specs.watchr'
10
- test: "echo 'SPECTACULARRR!'"
10
+ test: "echo 'SPECTACULARRR!'"
11
+ git:pull: 'git pull'
12
+ svn:up: 'svn update'
13
+ textmate: 'mate .'
@@ -1,3 +1,3 @@
1
- %W{app command version}.each {|r| require "elscripto/#{r}"}
1
+ %W{app command version options}.each {|r| require "elscripto/#{r}"}
2
2
  module Elscripto
3
3
  end
@@ -22,7 +22,11 @@ module Elscripto # :nodoc:
22
22
 
23
23
  class NoDefinitionsError < Exception # :nodoc:
24
24
  def initialize
25
- super "No definitions in your configuration file. What's the deal, guy?"
25
+ super "No commands or definitions gived.\n
26
+ You need to specify at least one of the following:
27
+ --file CONFIG_FILE
28
+ --commands CMD1;CMD2...
29
+ --definitions DEF1;DE2..."
26
30
  end
27
31
  end
28
32
 
@@ -36,31 +40,72 @@ module Elscripto # :nodoc:
36
40
  # Initialize it by passing a config file to it.
37
41
  # Default file path is <current_dir>/.elscripto
38
42
  class App
39
- attr_accessor :commands, :platform, :enviroment, :generated_script
43
+ attr_accessor :command, :opts, :commands, :platform, :enviroment, :generated_script
40
44
  CONFIG_FILE = File.join('.','.elscripto')
41
45
 
42
- def initialize opts_file, opts = {}
46
+ def initialize opts
47
+ @opts = opts
43
48
  @commands = []
49
+ @command = @opts.command
44
50
  @generated_script = ""
45
51
  @platform = self.class.get_platform(RbConfig::CONFIG['host_os'])
46
52
  first_run?
47
- @enviroment = opts.delete(:enviroment) || :production
48
- config_file = opts_file ? opts_file : CONFIG_FILE
49
- raise ArgumentError.new "Elscripto needs a config file spectacularrr" unless File.exists?(config_file)
50
- opts = YAML.load_file(config_file)
51
- raise Elscripto::NoDefinitionsError.new unless opts['commands'].class == Array
52
- opts['commands'].each do |cmd|
53
+ @enviroment = @opts.enviroment
54
+
55
+ if @command == 'start'
56
+ expand_commands!
57
+ add_adhoc_commands!
58
+ raise NoDefinitionsError if @commands.size == 0
59
+ end
60
+ end
61
+
62
+ def expand_commands!
63
+ # load configuration from file
64
+ if File.exists?(@opts.config_file)
65
+ file_opts = YAML.load_file(@opts.config_file)
66
+ @commands << file_opts['commands'] if file_opts['commands'].class == Array
67
+ end
68
+ # add in definitions
69
+ @commands << @opts.definitions unless @opts.definitions.size == 0
70
+
71
+ @commands = @commands.flatten.map do |cmd|
53
72
  case cmd.class.to_s
54
73
  when 'Hash'
55
- @commands << Command.new(cmd['name'], :command => cmd['command'])
74
+ Command.new(cmd['name'], :command => cmd['command'])
56
75
  when 'String'
57
- @commands << Command.new(cmd)
76
+ Command.new(cmd)
58
77
  end
59
78
  end
60
79
  end
61
80
 
81
+ def add_adhoc_commands!
82
+ # add in incoming adhoc commands
83
+ i = 1
84
+ @opts.commands.each do |c|
85
+ @commands << Command.new("cmd#{i}",:command => c)
86
+ i+=1
87
+ end
88
+ end
89
+
62
90
  def exec!
91
+ send(@command.to_sym)
92
+ end
93
+
94
+ def init
95
+ print "\nInitializing elscripto...".yellow
96
+ begin
97
+ self.class.init!
98
+ puts_unless_test " done."
99
+ puts_unless_test "Before continuing, update ./.elscripto with the desired script definitions\n\n".yellow
100
+ rescue Elscripto::AlreadyInitializedError
101
+ puts_unless_test " nah, it's already there!\n".green
102
+ end
103
+ end
104
+
105
+ def start
63
106
  raise Elscripto::NoDefinitionsError.new if self.commands.size == 0
107
+
108
+ puts_unless_test 'Starting ElScripto Spctacularrr!'.green
64
109
  case self.platform
65
110
  # tell application "Terminal"
66
111
  # activate
@@ -153,11 +198,15 @@ done}
153
198
  File.open(global_conf_file,'w') do |f|
154
199
  f.write(File.read(File.join(File.dirname(__FILE__),'..','..','config','elscripto.conf.yml')))
155
200
  end
156
- puts "Wrote global configuration to #{global_conf_file}".yellow
201
+ puts_unless_test "Wrote global configuration to #{global_conf_file}".yellow
157
202
  end
158
203
  end
159
204
  end
160
205
 
206
+ def puts_unless_test msg
207
+ puts msg unless enviroment == :test
208
+ end
209
+
161
210
  class << self
162
211
  def init!
163
212
  if File.exists?(CONFIG_FILE)
@@ -0,0 +1,68 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+ require 'fileutils'
4
+
5
+ module Elscripto
6
+ class InvalidCommandError < StandardError
7
+ end
8
+
9
+ class Options
10
+ VALID_COMMANDS = %W[init start]
11
+
12
+ # A customized OptionsParser
13
+ def self.parse(command,args)
14
+ # The options specified on the command line will be collected in *options*.
15
+ # We set default values here.
16
+ options = OpenStruct.new
17
+ options.verbose = false
18
+ options.path = FileUtils.pwd
19
+ options.command = command
20
+ options.config_file = './.elscripto'
21
+ options.commands = options.definitions = []
22
+ options.enviroment = :production
23
+ opts = OptionParser.new do |opts|
24
+ opts.program_name = 'elscripto'
25
+ opts.banner = "Usage: #{opts.program_name} init|start [options]".green
26
+ opts.separator ""
27
+ opts.separator "Options:".green
28
+
29
+ opts.on('-p','--path PATH',"Set elscripto's working directory") do |path|
30
+ options.path = path
31
+ end
32
+
33
+ opts.on('-c','--commands CMD1;CMD2;CMD3...','Pass a list of comma-separated commands') do |cmds|
34
+ options.commands = cmds.split(';').map(&:strip)
35
+ end
36
+
37
+ opts.on('-d','--definitions DEF1;DEF2;DEF3...','Pass a list of comma-separated command definitions') do |defs|
38
+ options.definitions = defs.split(';').map(&:strip)
39
+ end
40
+
41
+ opts.on('-f','--file CONFIG FILE PATH','Pass a path to a config file') do |conf_file|
42
+ options.config_file = conf_file
43
+ end
44
+
45
+ opts.on('-e','--enviroment [production|development]','Define runtime enviroment') do |env|
46
+ options.enviroment = env.to_sym
47
+ end
48
+ end
49
+
50
+ opts.separator ""
51
+ opts.separator "Common options:".green
52
+
53
+ opts.on_tail("-h", "--help", "Show this message") do
54
+ puts opts
55
+ exit
56
+ end
57
+
58
+ opts.on_tail("-v", "--version", "Show version") do
59
+ puts "#{opts.program_name} #{Elscripto::VERSION}\n(c) 2013, Achillefs Charmpilas".green
60
+ exit
61
+ end
62
+
63
+ opts.parse!(args)
64
+ raise Elscripto::InvalidCommandError, "Please specify a valid command [#{VALID_COMMANDS.join('|')}]" unless VALID_COMMANDS.include?(options.command)
65
+ options
66
+ end
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Elscripto
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -16,7 +16,7 @@ describe Elscripto::App do
16
16
  end
17
17
  end
18
18
 
19
- subject { Elscripto::App.new 'spec/files/sample_options.yml', :enviroment => :development }
19
+ subject { Elscripto::App.new(Elscripto::Options.parse('start',%W{-e test -d spork;autotest;rails:server;rails:console})) }
20
20
 
21
21
  describe 'with valid options' do
22
22
  it { subject.commands.size.should eq(4) }
@@ -27,12 +27,18 @@ describe Elscripto::App do
27
27
  end
28
28
 
29
29
  describe 'with invalid options' do
30
- subject { Elscripto::App.new 'spec/files/nonexistent_command.yml' }
30
+ subject {
31
+ conf = Elscripto::Options.parse('start',%W{-f spec/files/nonexistent_command.yml})
32
+ Elscripto::App.new(conf)
33
+ }
31
34
  it { expect { subject }.to raise_error(ArgumentError) }
32
35
  end
33
36
 
34
37
  describe 'with inline command input' do
35
- subject { Elscripto::App.new 'spec/files/new_definition.yml' }
38
+ subject {
39
+ conf = Elscripto::Options.parse('start',%W{-f spec/files/new_definition.yml})
40
+ Elscripto::App.new(conf)
41
+ }
36
42
  it { subject.commands.last.system_call.should eq('rake log:clear') }
37
43
  it { subject.commands.last.name.should eq('rails:logs') }
38
44
  end
@@ -65,7 +71,7 @@ describe Elscripto::App do
65
71
  end
66
72
 
67
73
  describe "with no definitions" do
68
- it { expect { Elscripto::App.new('spec/files/empty.yml') }.to raise_error(Elscripto::NoDefinitionsError) }
74
+ it { expect { Elscripto::App.new(Elscripto::Options.parse('start',[])) }.to raise_error(Elscripto::NoDefinitionsError) }
69
75
  end
70
76
  end
71
77
  end
@@ -0,0 +1,50 @@
1
+ require 'elscripto'
2
+ describe Elscripto::Options do
3
+ let(:cmd) { 'start' }
4
+ subject { Elscripto::Options }
5
+ describe 'defaults' do
6
+ subject { Elscripto::Options.parse(cmd,[]) }
7
+ its(:verbose) { should eq(false) }
8
+ its(:path) { should eq(FileUtils.pwd) }
9
+ its(:command) { should eq(cmd) }
10
+ its(:config_file) { should eq('./.elscripto') }
11
+ end
12
+
13
+ describe 'enviroment' do
14
+ it { subject.parse(cmd,%W{-e development}).enviroment.should eq(:development) }
15
+ it { subject.parse(cmd,%W{--enviroment=development}).enviroment.should eq(:development) }
16
+ end
17
+
18
+ describe 'invalid command' do
19
+ it {expect { subject.parse('random',[])}.to raise_error(Elscripto::InvalidCommandError) }
20
+ end
21
+
22
+ describe 'path options' do
23
+ let(:path) { '/test/path' }
24
+
25
+ describe '--path PATH' do
26
+ it { subject.parse(cmd,%W{-p #{path}}).path.should eq(path) }
27
+ it { subject.parse(cmd,%W{--path #{path}}).path.should eq(path) }
28
+ end
29
+
30
+ describe '--file PATH' do
31
+ it { subject.parse(cmd,%W{-f #{path}}).config_file.should eq(path) }
32
+ it { subject.parse(cmd,%W{--file #{path}}).config_file.should eq(path) }
33
+ end
34
+ end
35
+
36
+ describe 'array options' do |variable|
37
+ let(:commands) { 'cmd1;cmd2; cmd3 ;cmd4' }
38
+ let(:parsed) { %W{cmd1 cmd2 cmd3 cmd4}}
39
+
40
+ describe '--commands CMDS' do
41
+ it { subject.parse(cmd,%W{-c #{commands}}).commands.should eq(parsed) }
42
+ it { subject.parse(cmd,%W{--commands #{commands}}).commands.should eq(parsed) }
43
+ end
44
+
45
+ describe '--definitions DEFS' do
46
+ it { subject.parse(cmd,%W{-d #{commands}}).definitions.should eq(parsed) }
47
+ it { subject.parse(cmd,%W{--definitions #{commands}}).definitions.should eq(parsed) }
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elscripto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-01 00:00:00.000000000Z
12
+ date: 2013-01-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nutrun-string
16
- requirement: &2152682660 !ruby/object:Gem::Requirement
16
+ requirement: &2164952280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152682660
24
+ version_requirements: *2164952280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2164735980 !ruby/object:Gem::Requirement
27
+ requirement: &2164985120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2164735980
35
+ version_requirements: *2164985120
36
36
  description: Console window group automation for developers
37
37
  email:
38
38
  - ac@humbuckercode.co.uk
@@ -54,6 +54,7 @@ files:
54
54
  - lib/elscripto.rb
55
55
  - lib/elscripto/app.rb
56
56
  - lib/elscripto/command.rb
57
+ - lib/elscripto/options.rb
57
58
  - lib/elscripto/version.rb
58
59
  - spec/command_spec.rb
59
60
  - spec/elscripto_spec.rb
@@ -65,6 +66,7 @@ files:
65
66
  - spec/files/nonexistent_command.yml
66
67
  - spec/files/osascript.txt
67
68
  - spec/files/sample_options.yml
69
+ - spec/options_spec.rb
68
70
  homepage: http://github.com/Achillefs/elscripto
69
71
  licenses:
70
72
  - MIT
@@ -101,3 +103,4 @@ test_files:
101
103
  - spec/files/nonexistent_command.yml
102
104
  - spec/files/osascript.txt
103
105
  - spec/files/sample_options.yml
106
+ - spec/options_spec.rb