Permalink
Browse files

init 2

  • Loading branch information...
1 parent a19e2e2 commit bad63e470f02ff6c6da3ecda7eeb5befa4471efc @gutenye committed Jan 29, 2012
View
@@ -1,6 +1,7 @@
source :rubygems
gem "thor"
+gem "optimism", :path => "/home/guten/dev/one/optimism"
group :development do
gem "rspec"
View
@@ -0,0 +1,44 @@
+PATH
+ remote: /home/guten/dev/one/optimism
+ specs:
+ optimism (3.0.4)
+ hike (~> 1.2.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ diff-lcs (1.1.3)
+ hike (1.2.1)
+ multi_json (1.0.4)
+ pa (1.0.3)
+ tagen (~> 1.0.0)
+ pd (1.0.3)
+ rag (1.0.7)
+ pa (~> 1.0.0)
+ tagen (~> 1.0.0)
+ thor (~> 0.14.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ tagen (1.0.4)
+ activesupport
+ pd
+ thor (0.14.6)
+ watchr (0.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ optimism!
+ rag
+ rspec
+ thor
+ watchr
View
@@ -1,14 +0,0 @@
-#!/usr/bin/env ruby
-require '<%=project%>/cli'
-
-begin
- <%=project.capitalize%>::CLI.start
-rescue <%=project.capitalize%>::<%=project.capitalize%>Error => e
- <%=project.capitalize%>.ui.error e.message
- <%=project.capitalize%>.ui.debug e.backtrace.join("\n")
- exit 1
-rescue Interrupt => e
- <%=project.capitalize%>.ui.error "\nQuitting..."
- <%=project.capitalize%>.ui.debug e.backtrace.join("\n")
- exit 1
-end
View
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+require_relative "../lib/oldtime/cli"
+
+begin
+ Oldtime::CLI.start
+rescue Oldtime::Error => e
+ Oldtime.ui.error e.message
+ Oldtime.ui.debug e.backtrace.join("\n")
+ exit 1
+rescue Interrupt => e
+ Oldtime.ui.error "\nQuitting..."
+ Oldtime.ui.debug e.backtrace.join("\n")
+ exit 1
+end
View
@@ -1,21 +0,0 @@
-libdir = File.dirname(__FILE__)
-$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
-
-module OldTime
- autoload :VERSION, "old_time/version"
- autoload :Core, "old_time/core"
-end
-
-module Kernel
-private
-
- include OldTime::Core
-
- def backup(&blk)
- @backup = blk
- end
-
- def restore(&blk)
- @restore = blk
- end
-end
View
@@ -1,6 +0,0 @@
-module OldTime
- class CLI < Thor
-
-
- end
-end
View
@@ -0,0 +1,43 @@
+libdir = File.dirname(__FILE__)
+$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
+
+ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
+require "bundler/setup"
+Bundler.require
+
+module Oldtime
+ autoload :VERSION, "oldtime/version"
+ autoload :UI, "oldtime/ui"
+ autoload :Core, "oldtime/core"
+
+ Error = Class.new Exception
+ FatalError = Class.new Exception
+
+ class << self
+ attr_accessor :ui
+
+ def ui
+ @ui ||= UI.new
+ end
+ end
+end
+
+Rc = Optimism.require "oldtime/rc"
+
+module Kernel
+private
+
+ include Oldtime::Core
+
+ def configure(data, &blk)
+ Rc << Optimism(data, &blk)
+ end
+
+ def backup(instance=:default, &blk)
+ Rc.backup_blks[instance] = blk
+ end
+
+ def restore(instance=:default, &blk)
+ Rc.restore_blks[instance] = blk
+ end
+end
@@ -1,4 +1,4 @@
-module OldTime
+module Oldtime
module ArchLinux
def backup_packages
View
@@ -0,0 +1,44 @@
+module Oldtime
+ class CLI < Thor
+ include Thor::Actions
+
+ # check_unknown_options!
+
+ # default_task :install
+ class_option "no-color", :type => :boolean, :banner => "Disable colorization in output"
+ class_option "verbose", :aliases => "-V", :type => :boolean, :banner => "Enable verbose output mode",
+
+ def initialize(*)
+ super
+ the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
+ Bundler.ui = UI::Shell.new(the_shell)
+ Bundler.ui.debug! if options["verbose"]
+ end
+
+ desc "backup <profile> [instance]", "begin backup process."
+ # method_option "x", :aliases => "-x", :default => "x", :type => :string, :banner => "NAME", :desc => "x"
+ def backup(profile, instance=:default)
+ load_profile profile
+
+ Rc.backup_blks[instance].call
+ end
+
+ desc "restore <profile> [instance]", "begin restore process."
+ def restore(profile, instance=:default)
+ load_profile profile
+
+ Rc.restore_blks[instance].call
+ end
+
+private
+
+ def load_profile(profile)
+ file = "#{ENV['HOME']}/#{profile}/#{profile}.conf"
+ if Pa.exists?(file)
+ load file
+ else
+ raise Error, "can't find the profile configuration file -- #{file}"
+ end
+ end
+ end
+end
@@ -1,4 +1,4 @@
-module OldTime
+module Oldtime
module Core
def rsync
puts "rsync"
View
@@ -0,0 +1,8 @@
+backup_blks = {}
+restore_blks = {}
+
+backup:
+ rsync.options = ""
+
+restore:
+ rsync.options = ""
View
@@ -0,0 +1,56 @@
+module Oldtime
+ class UI
+ def warn(message)
+ end
+
+ def debug(message)
+ end
+
+ def error(message)
+ end
+
+ def info(message)
+ end
+
+ def confirm(message)
+ end
+
+ class Shell < UI
+ attr_writer :shell
+
+ def initialize(shell)
+ @shell = shell
+ @quiet = false
+ @debug = ENV['DEBUG']
+ end
+
+ def debug(msg)
+ @shell.say(msg) if @debug && !@quiet
+ end
+
+ def info(msg)
+ @shell.say(msg) if !@quiet
+ end
+
+ def confirm(msg)
+ @shell.say(msg, :green) if !@quiet
+ end
+
+ def warn(msg)
+ @shell.say(msg, :yellow)
+ end
+
+ def error(msg)
+ @shell.say(msg, :red)
+ end
+
+ def be_quiet!
+ @quiet = true
+ end
+
+ def debug!
+ @debug = true
+ end
+ end
+ end
+end
@@ -1,3 +1,3 @@
-module ABT
+module Oldtime
VERSION="0.1.0"
end
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,24 @@
+require "spec_helper"
+
+
+describe Kernel do
+ it "#configure" do
+ configure <<-EOF
+ a = 1
+ EOF
+
+ Rc.a.should == 1
+ end
+
+ it "#backup" do
+ backup(:foo){ "backup" }
+
+ Rc.backup_blks[:foo].call.should == "backup"
+ end
+
+ it "#restore" do
+ restore(:foo){ "restore" }
+
+ Rc.restore_blks[:foo].call.should == "restore"
+ end
+end
View
@@ -0,0 +1 @@
+require "oldtime"
View
No changes.

0 comments on commit bad63e4

Please sign in to comment.