Lidia 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ *~
2
+ rdoc
3
+ pkg
@@ -0,0 +1,13 @@
1
+ === 0.0.2 2010-12-30
2
+
3
+ * 1 major enhancement:
4
+ * moved to gitorious
5
+ * uploaded to rubygems
6
+
7
+ === 0.0.1 2010-12-28
8
+
9
+ * 1 major enhancement:
10
+ * work on dar definition 60%
11
+ * work on gpg definition 5%
12
+ * work on ls definition 5%
13
+ * some tests
@@ -0,0 +1,20 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lidia.gemspec
7
+ lib/lidia.rb
8
+ lib/lidia/command.rb
9
+ lib/lidia/parameter.rb
10
+ lib/lidia/source.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ spec/lidia/command_spec.rb
15
+ sources/ls.lidia.yml
16
+ sources/gpg.lidia.yml
17
+ sources/dar.lidia.yml
18
+
19
+
20
+
@@ -0,0 +1,5 @@
1
+
2
+ For more information on lidia, see http://lidia.rubyforge.org
3
+
4
+
5
+
@@ -0,0 +1,134 @@
1
+ = LIDIA
2
+
3
+ * http://gitorious/gnoxys/lidia
4
+
5
+ == DESCRIPTION:
6
+
7
+ Lidia is a yml based command contructor class. Aims to be easy to use and to provide an easy way to remember tons of commands
8
+
9
+ == SYNOPSIS:
10
+
11
+ Lidia's is written to provide an easy way to manage commands calls. Commands structure can be defined in an easy yaml file.
12
+
13
+ # $your editor ls.lidia.yml
14
+ : ==parameters:
15
+ :columns:
16
+ :option: -l
17
+ :description: listing format@
18
+
19
+ By default, lidia loads definition files from gem installation folder ../source, or you can pass with <tt>:definition_file</tt> the location
20
+
21
+ >> Lidia::Command.new('ls', {}, :definition_file => 'ls.lidia.yml')
22
+ => Lidia::Command
23
+ + name: ls,
24
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
25
+ + parameters:
26
+ * name: columns group: option , value: nil
27
+
28
+ Values can be passed as argument on new, or creating by block
29
+
30
+ >> Lidia::Command.new('ls', {:columns => true })
31
+ ?> Lidia::Command.new('ls') do |l|
32
+ ?> l.columns = true
33
+ >> end
34
+ => Lidia::Command
35
+ + name: ls,
36
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
37
+ + parameters:
38
+ * name: columns group: option , value: true
39
+
40
+ Once u have defined all the parameters that your command will use, define which actions can be done, por example, list_by_columns
41
+
42
+ # your editor ls.lidia.yml
43
+ # :actions:
44
+ # :list_by_columns:
45
+ # :parameters:
46
+ # :required: [ :columns ]
47
+
48
+ Now ask for <tt>command_for</tt> lidia list_by_columns
49
+
50
+ >> l = Lidia::Command.new('ls', {:columns => nil })
51
+ => Lidia::Command
52
+ + name: ls,
53
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
54
+ + parameters:
55
+ * name: columns group: option , value: nil
56
+
57
+ >> l.command_for(:list_by_columns)
58
+ ArgumentError: Parameter columns required but not valid
59
+
60
+ Ooops, parameter -l is required, to list_by_columns action, so set it to true
61
+
62
+ >> l.columns = true
63
+ => true
64
+ >> l.command_for(:list_by_columns)
65
+ => "/bin/ls -l"
66
+
67
+ We want sometimes, list other directory. so prepare defintion file to get an argument
68
+
69
+ # $your editor ls.lidia.yml
70
+ # :parameters:
71
+ # :list_what:
72
+ # :description: what do u want to list?
73
+
74
+ this option can be used for listing_by_columns to, but it is not mandatary
75
+
76
+ # $your editor ls.lidia.yml
77
+ # :actions:
78
+ # :list_by_columns:
79
+ # :parameters:
80
+ # :required: [ :columns ]
81
+ # :optional: [ :list_what ]
82
+
83
+ Now, no exceptions is raised, but argument can be used
84
+
85
+ >> l = Lidia::Command.new('ls', {:columns => true })
86
+ => Lidia::Command
87
+ + name: ls,
88
+ + definition file at:/var/www/lidia/sources/ls.lidia.yml
89
+ + parameters:
90
+ * name: columns group: option , value: true
91
+ * name: list_what group: argument , value: nil
92
+
93
+ >> l.command_for(:list_by_columns)
94
+ => "/bin/ls -l "
95
+ >> l.list_what = '/tmp'
96
+ => "/tmp"
97
+ >> l.command_for(:list_by_columns)
98
+ => "/bin/ls -l \"/tmp\" "
99
+
100
+
101
+
102
+
103
+ == REQUIREMENTS:
104
+
105
+ * FIX (list of requirements)
106
+
107
+ == INSTALL:
108
+
109
+ * FIX (sudo gem install, anything else)
110
+
111
+ == LICENSE:
112
+
113
+ (The MIT License)
114
+
115
+ Copyright (c) 2010 FIXME full name
116
+
117
+ Permission is hereby granted, free of charge, to any person obtaining
118
+ a copy of this software and associated documentation files (the
119
+ 'Software'), to deal in the Software without restriction, including
120
+ without limitation the rights to use, copy, modify, merge, publish,
121
+ distribute, sublicense, and/or sell copies of the Software, and to
122
+ permit persons to whom the Software is furnished to do so, subject to
123
+ the following conditions:
124
+
125
+ The above copyright notice and this permission notice shall be
126
+ included in all copies or substantial portions of the Software.
127
+
128
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
129
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
130
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
131
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
132
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
133
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
134
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+ require 'bundler'
8
+ require File.join(File.dirname(__FILE__), 'lib', 'lidia')
9
+
10
+
11
+ Rspec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = ["--color"]
13
+ end
14
+
15
+ task :default => :spec
16
+
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Lidia'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README.rdoc')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'lidia/command'
5
+ require 'lidia/parameter'
6
+ require 'lidia/source'
7
+
8
+ module Lidia
9
+ VERSION = '0.0.2'
10
+ end
@@ -0,0 +1,181 @@
1
+ module Lidia #:nodoc:#
2
+ class Command
3
+
4
+ SYNTAX_REX = /\%([a-z_]*)\{([a-z_]*)\}/
5
+
6
+ attr_reader :name
7
+ attr_reader :source
8
+ attr_reader :config
9
+ attr_reader :definition_file
10
+ attr_reader :path
11
+ attr_reader :options
12
+
13
+ attr_accessor :parameters
14
+ attr_accessor :current_action_name
15
+ attr_accessor :current_action_config
16
+ attr_accessor :current_action_cmd
17
+
18
+
19
+ # Lidia's is written to provide an easy way to manage commands calls. Commands structure can be defined in an easy yaml file.
20
+ #
21
+ # # $your editor ls.lidia.yml
22
+ # :parameters:
23
+ # :columns:
24
+ # :option: -l
25
+ # :description: listing format
26
+ #
27
+ # By default, lidia loads definition files from gem installation folder ../source, or you can pass with <tt>:definition_file</tt> the location
28
+ #
29
+ # >> Lidia::Command.new('ls', {}, :definition_file => 'ls.lidia.yml')
30
+ # => Lidia::Command
31
+ # + name: ls,
32
+ # + definition file at:/var/www/lidia/sources/ls.lidia.yml
33
+ # + parameters:
34
+ # * name: columns group: option , value: nil
35
+ #
36
+ # Values can be passed as argument on new, or creating by block
37
+ #
38
+ # >> Lidia::Command.new('ls', {:columns => true })
39
+ # ?> Lidia::Command.new('ls') do |l|
40
+ # ?> l.columns = true
41
+ # >> end
42
+ # => Lidia::Command
43
+ # + name: ls,
44
+ # + definition file at:/var/www/lidia/sources/ls.lidia.yml
45
+ # + parameters:
46
+ # * name: columns group: option , value: true
47
+ #
48
+ # Once u have defined all the parameters that your command will use, define which actions can be done, por example, list_by_columns
49
+ #
50
+ # # your editor ls.lidia.yml
51
+ # # :actions:
52
+ # # :list_by_columns:
53
+ # # :parameters:
54
+ # # :required: [ :columns ]
55
+ #
56
+ # Now ask for <tt>command_for</tt> lidia list_by_columns
57
+ #
58
+ # >> l = Lidia::Command.new('ls', {:columns => nil })
59
+ # => Lidia::Command
60
+ # + name: ls,
61
+ # + definition file at:/var/www/lidia/sources/ls.lidia.yml
62
+ # + parameters:
63
+ # * name: columns group: option , value: nil
64
+ #
65
+ # >> l.command_for(:list_by_columns)
66
+ # ArgumentError: Parameter columns required but not valid
67
+ #
68
+ # Ooops, parameter -l is required, to list_by_columns action, so set it to true
69
+ #
70
+ # >> l.columns = true
71
+ # => true
72
+ # >> l.command_for(:list_by_columns)
73
+ # => "/bin/ls -l"
74
+ #
75
+ # We want sometimes, list other directory. so prepare defintion file to get an argument
76
+ #
77
+ # # $your editor ls.lidia.yml
78
+ # # :parameters:
79
+ # # :list_what:
80
+ # # :description: what do u want to list?
81
+ #
82
+ # this option can be used for listing_by_columns to, but it is not mandatary
83
+ #
84
+ # # $your editor ls.lidia.yml
85
+ # # :actions:
86
+ # # :list_by_columns:
87
+ # # :parameters:
88
+ # # :required: [ :columns ]
89
+ # # :optional: [ :list_what ]
90
+ #
91
+ # Now, no exceptions is raised, but argument can be used
92
+ #
93
+ # >> l = Lidia::Command.new('ls', {:columns => true })
94
+ # => Lidia::Command
95
+ # + name: ls,
96
+ # + definition file at:/var/www/lidia/sources/ls.lidia.yml
97
+ # + parameters:
98
+ # * name: columns group: option , value: true
99
+ # * name: list_what group: argument , value: nil
100
+ #
101
+ # >> l.command_for(:list_by_columns)
102
+ # => "/bin/ls -l "
103
+ # >> l.list_what = '/tmp'
104
+ # => "/tmp"
105
+ # >> l.command_for(:list_by_columns)
106
+ # => "/bin/ls -l \"/tmp\" "
107
+ def initialize(command_name, parameters = {}, options = {})
108
+ @name = command_name
109
+ @options = options
110
+
111
+ @source = Lidia::Source.new({:include => (options[:definition_file] ? File.dirname(options[:definition_file]) : nil) })
112
+ @config = load_config
113
+ @path = @options[:path] || @config[:path] || %x[ which #{ command_name } ].strip
114
+
115
+ @parameters = Lidia::Parameter.build(self, parameters)
116
+
117
+ @parameters.each do |parameter|
118
+ get_block = Proc.new{ self.get_parameter_value(parameter.name) }
119
+ set_block = Proc.new{ |v| self.set_parameter_value(parameter.name, v) }
120
+
121
+ self.class.send(:define_method, "#{ parameter.name }", get_block)
122
+ self.class.send(:define_method, "#{ parameter.name }=", set_block)
123
+ end
124
+
125
+ yield self if block_given?
126
+ end
127
+
128
+ def command_for(name)
129
+ build_action(name) ? @current_action_cmd : raise(ArgumentError, "not valid action #{ name }")
130
+ end
131
+
132
+ def inspect
133
+ %(#{ self.class.name }
134
+ + name: #{ @name },
135
+ + definition file at:#{ @definition_file }
136
+ + parameters:
137
+ #{ @parameters.sort{|a,b| a.name.to_s <=> b.name.to_s }.map(&:inspect).join("\n ") }
138
+ )
139
+ end
140
+
141
+ def get_parameter_value(parameter_name)
142
+ parameter = @parameters.select{ |p| p.name == parameter_name }.first
143
+ parameter ? parameter.value : raise(NoMethodError)
144
+ end
145
+
146
+ def set_parameter_value(parameter_name, value)
147
+ parameter = @parameters.select{ |p| p.name == parameter_name }.first
148
+ parameter ? (parameter.value = value) : raise(NoMethodError)
149
+ end
150
+
151
+ private
152
+ # Load definition file as execpted YAML file.
153
+ # FIXME more information to this method
154
+ def load_config
155
+ @definition_file = @source.find(@name)
156
+ YAML.load_file(@definition_file)
157
+ end
158
+
159
+ # Build action set variables to build command for an action.
160
+ # Return buildt command
161
+ def build_action(action)
162
+ @current_action_name = action || raise(ArgumentError, "action is nil #{ action }")
163
+ @current_action_config = @config[:actions][action] || raise(ArgumentError, "no valid config for action #{ action }")
164
+
165
+ validate_and_build_command
166
+ end
167
+
168
+ def validate_and_build_command
169
+ valid_action? ? build_command : false
170
+ end
171
+
172
+ # Check if current_action_name and current_action_config are not nil and command can be built.
173
+ def valid_action?
174
+ !@current_action_name.nil? || !@current_action_config.nil?
175
+ end
176
+
177
+ def build_command
178
+ @current_action_cmd = "#{ @path } #{ Lidia::Parameter.parameters_for_command_line(@parameters, @current_action_config[:parameters][:required]) }"
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,171 @@
1
+ module Lidia #:nodoc:#
2
+ class Parameter
3
+
4
+ COMMAND_LINE_SORT = [ 'option_required', 'option', 'argument_required', 'argument' ]
5
+
6
+ attr_reader :command
7
+ attr_reader :name
8
+ attr_reader :required_argument
9
+ attr_reader :group
10
+ attr_reader :prefix
11
+
12
+
13
+ attr_accessor :required_by_action
14
+ attr_accessor :value
15
+
16
+
17
+ def self.build(command, inc_parameteres = {})
18
+ collection = []
19
+ command.config[:parameters].each do |parameter, config|
20
+ config ||= {}
21
+ collection << new(command, parameter, config, inc_parameteres[parameter])
22
+ end
23
+ collection
24
+ end
25
+
26
+ def self.parameters_for_command_line(command_parameters, required_parameters)
27
+
28
+ cli_parameters = []
29
+ command_parameters.each do |parameter|
30
+
31
+ group = parameter.group.to_s
32
+
33
+ if required_parameters.include?(parameter.name)
34
+ raise ArgumentError, "Parameter #{ parameter.name } required but not valid" unless parameter.valid?
35
+ group += '_required'
36
+ end
37
+
38
+ cli_parameters << { :group => group, :to_cli => parameter.to_cli } if parameter.to_cli
39
+ end
40
+
41
+
42
+ cli_parameters.sort{ |a,b| COMMAND_LINE_SORT.index(a[:group]) <=> COMMAND_LINE_SORT.index(b[:group]) }.map{ |p| p[:to_cli] }.join(' ')
43
+ end
44
+
45
+
46
+ def initialize(command, name, config, incoming_value = nil)
47
+ @command = command
48
+ @name = name
49
+ @value = incoming_value || config[:default] || nil
50
+ set_attributes(config)
51
+ end
52
+
53
+ def to_cli
54
+ case value
55
+ when TrueClass
56
+ return "#{ @prefix } "
57
+ when String
58
+ return "#{ @prefix } #{ @value.inspect } "
59
+ when Array
60
+ if @multiple
61
+ string = @value.inject('') do |string, v|
62
+ string << "#{ @prefix } #{ v } "
63
+ end
64
+ return string
65
+ else
66
+ string = "#{ @prefix } #{ @value.join(@join) }"
67
+ return string
68
+ end
69
+ else
70
+ return false
71
+ end
72
+ end
73
+
74
+ def valid?
75
+ !to_cli.is_a?(FalseClass)
76
+ end
77
+
78
+ def inspect
79
+ %( * name: #{ @name.to_s.ljust(20) } group: #{ @group.to_s.ljust(10) }, value: #{ @value.inspect } )
80
+ end
81
+
82
+ private
83
+ def set_attributes(config)
84
+ @required_argument = config[:required_argument].is_a?(TrueClass)
85
+ @required_by_action = false
86
+ @group = config[:option].nil? ? :argument : :option
87
+ @multiple = config[:multiple]
88
+ @join = config[:join] || ' '
89
+
90
+ if @group == :option
91
+ @prefix = config[:option]
92
+ end
93
+
94
+ end
95
+
96
+
97
+
98
+
99
+
100
+
101
+ #
102
+ # def assert_parameter(name)
103
+ # build_parameter(name)
104
+ # end
105
+ #
106
+ # def assert_parameter!(name)
107
+ # build_parameter(name, true)
108
+ # end
109
+ #
110
+ #
111
+ # # FIXME modularize
112
+ # def build_parameter(name, required = false)
113
+ # config = @parameters[name]
114
+ # value = instance_variable_get("@#{ name }")
115
+ # string = parse_to_cli(name, value, config) || ''
116
+ # type = "#{ config[:type] }#{ required ? '_required' : '' }".to_sym
117
+ #
118
+ # if required and value.nil?
119
+ # raise(ArgumentError, "missing value for paramater #{ name }") if string.nil? and @raise_if_value_nil
120
+ # end
121
+ #
122
+ # { :value => string, :type => type }
123
+ # end
124
+ #
125
+ # def parse_to_cli(name, value, config)
126
+ # prefix = config[:option] ? config[:option] : ''
127
+ # if config[:required_argument] and value.nil?
128
+ # return nil
129
+ # else
130
+ # case value
131
+ # when TrueClass
132
+ # string = "#{ prefix } "
133
+ # when String
134
+ # string = "#{ prefix } #{ value.inspect } "
135
+ # when Array
136
+ # if config[:multiple]
137
+ # string = value.inject('') do |string, v|
138
+ # string << "#{ prefix } #{ v.inspect } "
139
+ # end
140
+ # else
141
+ # string = "#{ prefix } #{ value.join(',') } "
142
+ # end
143
+ # end
144
+ # return string
145
+ # end
146
+ # end
147
+ #
148
+ #
149
+ #
150
+ # def assert_parameters(inc_parameteres)
151
+ # valid_parameters = @config[:parameters]
152
+ #
153
+ # parameters = valid_parameters.inject({}) do |parameters, parameter|
154
+ # parameter_name = parameter.first
155
+ # parameter_config = parameter.last
156
+ #
157
+ # @parameters[parameter_name] = parameter_config
158
+ # @parameters[parameter_name][:def_value] = inc_parameteres[parameter_name] || (parameter_config and parameter_config[:default] ? parameter_config[:default] : nil)
159
+ # @parameters[parameter_name][:type] = parameter_config[:option] ? :option : :argument
160
+ #
161
+ # inc_parameteres.delete(parameter_name)
162
+ # parameters
163
+ # end
164
+ #
165
+ #
166
+ # unless inc_parameteres.empty?
167
+ # raise ArgumentError, "no valid parameter #{ inc_parameteres.keys.join(',') }"
168
+ # end || parameters
169
+ # end
170
+ end
171
+ end
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+
3
+ module Lidia
4
+ class Source
5
+
6
+ LIDIA_SOURCE_EXTENSION = 'lidia.yml'
7
+
8
+ attr_reader :paths
9
+
10
+ # = Lidia::Source
11
+ #
12
+ # This class manage source dir for lidia definition files.
13
+ def initialize(options = {})
14
+ @paths = []
15
+ unless options[:default].is_a?(FalseClass)
16
+ add_path(File.dirname(File.expand_path(__FILE__)) + '/../../sources')
17
+ end
18
+
19
+ add_path(options[:include]) if options[:include]
20
+ end
21
+
22
+ # include paths for definition_files
23
+ def add_path(paths)
24
+ case paths
25
+ when String
26
+ store_path(paths)
27
+ when Array
28
+ paths.each { |path| store_path(path) }
29
+ else
30
+ raise(ArgumentError, "Invalid path class for add_path. Expected Array, String, got #{ path.class }")
31
+ end
32
+ end
33
+
34
+ def find(program, options = {})
35
+ definition_file_name = "#{ program }.#{ LIDIA_SOURCE_EXTENSION }"
36
+ definition_file = @paths.inject('') do |definition_file, path|
37
+ Dir.chdir(path) do |dir|
38
+ definition_file = (File.exist?(File.join(dir, definition_file_name)) ? File.join(dir, definition_file_name) : '') if definition_file.empty?
39
+ definition_file
40
+ end
41
+ end
42
+ definition_file.empty? ? raise(ArgumentError, "Lidia couldnt find file definition `#{ definition_file }` at #{ @paths.join(', ') }") : definition_file
43
+ end
44
+
45
+
46
+ private
47
+ def store_path(path)
48
+ if not File.exists?(path)
49
+ raise(ArgumentError, "Path #{ path } doesnt exists")
50
+ elsif not File.directory?(path)
51
+ raise(ArgumentError, "Path #{ path } is not directory")
52
+ else
53
+ @paths << File.expand_path(path)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'lidia')
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "Lidia"
5
+ s.version = Lidia::VERSION
6
+ s.summary = "Lidia is a yml based command contructor class. Aims to be easy to use and to provide an easy way to remember tons of commands"
7
+ s.description = "Lidia is a yml based command contructor class. Aims to be easy to use and to provide an easy way to remember tons of commands"
8
+ s.authors = ['Gnoxys' ]
9
+ s.files = `git ls-files`.split("\n")
10
+ s.add_runtime_dependency('open4', '0.9.6')
11
+
12
+ s.add_development_dependency('rspec', '~> 2.3.0')
13
+
14
+ # s.add_development_dependency('capybara', '~> 0.3.9')
15
+ # s.add_development_dependency('sqlite3-ruby')
16
+ if RUBY_VERSION < '1.9'
17
+ s.add_development_dependency('ruby-debug', '~> 0.10.3')
18
+ end
19
+ # s.add_development_dependency('rspec-rails', '~> 2.0.0')
20
+ # s.add_development_dependency('factory_girl', '~> 1.3.2')
21
+ # s.add_development_dependency('forgery', '~> 0.3.6')
22
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/lidia.rb'}"
9
+ puts "Loading lidia gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,96 @@
1
+ :parameters:
2
+ :create:
3
+ :option: -c
4
+ :option_alias: [ --create ]
5
+ :description: creates a backup with the name based on <basename>
6
+ :required_argument: true
7
+ :extract:
8
+ :option: -x
9
+ :option_alias: [ --extract ]
10
+ :description: extracts files from the given backup
11
+ :required_argument: true
12
+ :list:
13
+ :option: -l
14
+ :option_alias: [ --list ]
15
+ :description: lists the contents of the given backup
16
+ :required_argument: true
17
+ :test:
18
+ :option: -t
19
+ :option_alias: [ --test ]
20
+ :description: checks the backup integrity
21
+ :required_argument: true
22
+ :root_backup:
23
+ :option: -R
24
+ :description: root point to start backup
25
+ :default: /
26
+ :required_argument: true
27
+ :exclude_files:
28
+ :option: [ -X ]
29
+ :description: exclude files for backup
30
+ :default: [ '*.dar' ]
31
+ :multiple: true
32
+ :required_argument: true
33
+ :include_files:
34
+ :option: [ -I ]
35
+ :description: exclude files for backup
36
+ :default: [ ]
37
+ :multiple: true
38
+ :required_argument: true
39
+
40
+
41
+ :compression:
42
+ :option: [ -m ]
43
+ :value: any
44
+ :file_size:
45
+ :option: [ -s ]
46
+ :default: 3000M
47
+
48
+ :no_warn:
49
+ :option: -w
50
+ :description: dont warn
51
+
52
+ :bzip_compression:
53
+ :option: [ -y ]
54
+ :required_argument: false
55
+
56
+ :zip_compression:
57
+ :option: [ -z ]
58
+ :required_argument: false
59
+
60
+ :store_empty_folders:
61
+ :option: [ -D ]
62
+ :non_interactive_mode:
63
+ :option: [ -Q ]
64
+ :required_argument: false
65
+
66
+ :exclude_to_compress:
67
+ :option: [ -Z ]
68
+ :exclude_folders:
69
+ :option: [ -P ]
70
+ :multiple: true
71
+
72
+
73
+ :decrypt_password:
74
+ :option: [ -K ]
75
+ :encrypt_password:
76
+ :option: [ -J ]
77
+ :backup_file:
78
+
79
+
80
+
81
+
82
+
83
+ :actions:
84
+ :do_backup:
85
+ :parameters:
86
+ :required: [ :backup_file, :root_backup ]
87
+ :optional: [ :no_warn, :compression, :store_empty_folders, :file_size, :bzip_compression, :non_interactive_mode, :exclude_to_compress, :exclude_files, :exclude_folders, :decrypt_password, :encrypt_password ]
88
+
89
+
90
+
91
+ # :syntax: '%option{kk1} %option{compression} %option{kk2} %option{dar_file_size} %option{kk3} %option{kk4} %option_required{root_backup} %argument{backup_file}'
92
+
93
+
94
+
95
+
96
+ # -Z '{{exclude_to_compress}}' -P '{{exclude_folders}}' -X '*.dar' -J {{dar_encrypt_password}} -K {{dar_decrypt_password}} {{backup_files}}"
@@ -0,0 +1,25 @@
1
+ :parameters:
2
+ :user_key:
3
+ :option: -r
4
+ :required_argument: true
5
+ :encrypt:
6
+ :option: -e
7
+ :decrypt_file:
8
+ :option: -d
9
+ :description: decrypt file
10
+ :required_argument: true
11
+ :passphrase:
12
+ :option: --passphrase
13
+ :description: passphrase encrypt
14
+ :required_argument: true
15
+
16
+
17
+ :actions:
18
+ :decrypt_file:
19
+ :parameters:
20
+ :required: [ :decrypt_file ]
21
+ :optional: [ :passphrase ]
22
+ :encrypt_data:
23
+ :parameters:
24
+ :required: [ :user_key, :encrypt ]
25
+ :optional: [ ]
@@ -0,0 +1,11 @@
1
+ :parameters:
2
+ :columns:
3
+ :option: -l
4
+ :description: listing format
5
+ :list_what:
6
+ :description: what do u want to list?
7
+ :actions:
8
+ :list_by_columns:
9
+ :parameters:
10
+ :required: [ :columns ]
11
+ :optional: [ :list_what ]
@@ -0,0 +1,46 @@
1
+ require './lib/lidia'
2
+ require './lib/lidia/command'
3
+
4
+ describe Lidia::Command do
5
+
6
+ describe "#creation" do
7
+ it "should create a new instance of command" do
8
+ l = Lidia::Command.new('ls')
9
+ end
10
+
11
+ it "should not create a new instance of command" do
12
+ begin
13
+ l = Lidia::Command.new('lss')
14
+ rescue
15
+ l.nil?
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#command_for" do
21
+ it "should not render ls -l action due columns option does not fix" do
22
+ l = Lidia::Command.new('ls')
23
+ begin
24
+ cmd = l.command_for(:list_by_columns)
25
+ rescue
26
+ cmd.nil?
27
+ end
28
+ end
29
+ it "should render ls -l. Argument set by block" do
30
+ l = Lidia::Command.new('ls') do |li|
31
+ li.columns = true
32
+ end
33
+ l.command_for(:list_by_columns) == "/bin/ls -l"
34
+ end
35
+ it "should render ls -l. Argument set by definition_method" do
36
+ l = Lidia::Command.new('ls')
37
+ l.columns = true
38
+ l.command_for(:list_by_columns) == "/bin/ls -l"
39
+ end
40
+
41
+
42
+ end
43
+
44
+
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Lidia
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Gnoxys
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-30 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: open4
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 55
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 6
34
+ version: 0.9.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 0
50
+ version: 2.3.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: ruby-debug
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 0
64
+ - 10
65
+ - 3
66
+ version: 0.10.3
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Lidia is a yml based command contructor class. Aims to be easy to use and to provide an easy way to remember tons of commands
70
+ email:
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - .gitignore
79
+ - History.txt
80
+ - Manifest.txt
81
+ - PostInstall.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - lib/lidia.rb
85
+ - lib/lidia/command.rb
86
+ - lib/lidia/parameter.rb
87
+ - lib/lidia/source.rb
88
+ - lidia.gemspec
89
+ - script/console
90
+ - script/destroy
91
+ - script/generate
92
+ - sources/dar.lidia.yml
93
+ - sources/gpg.lidia.yml
94
+ - sources/ls.lidia.yml
95
+ - spec/lidia/command_spec.rb
96
+ has_rdoc: true
97
+ homepage:
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.3.7
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Lidia is a yml based command contructor class. Aims to be easy to use and to provide an easy way to remember tons of commands
130
+ test_files: []
131
+