Skip to content

Commit

Permalink
Initial work on Purse::Cli - it can talk and run setup
Browse files Browse the repository at this point in the history
  • Loading branch information
quirkey committed Aug 8, 2008
1 parent 470dc93 commit c7c9611
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/purse
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env ruby
#

require File.join(File.dirname(__FILE__), '..', 'lib', 'purse')

Purse::Cli.run(ARGV)
1 change: 1 addition & 0 deletions lib/purse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
require 'purse/settings'
require 'purse/pocket'
require 'purse/note'
require 'purse/cli'
80 changes: 80 additions & 0 deletions lib/purse/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'highline/import'

module Purse
class Cli

# purse pursename #=> initialize or pull
# purse pursename notename #=> pocket.find(notename) if it doesnt exist first pull then ask if you want to create it
# purse pursename notename --edit #=> open in EDITOR save and push
# purse pursename push
# purse pursename pull
# purse settings/ purse # rerun settings
class << self
def run(args)
pocket_name = args.shift
note_name = args.shift
action = args.shift
if pocket_name == 'settings' || pocket_name.nil?
settings
elsif action
send(action.gsub('--'), pocket_name, note_name)
else
case note_name
when 'push'
push pocket_name
when 'pull'
pull pocket_name
when ''
when nil
init pocket_name
else
find(pocket_name, note_name)
end
end
end

protected
def settings
hr
h1('Purse /', :white)
h1('Setup utility')
hr
say("loading settings from : #{Settings.path}")
Settings.load
settings = {}
settings[:root_path] = ask("Root Path for pockets? ") {|q| q.default = Settings.get(:root_path) || File.join(File.expand_path('~'), '.purse', 'pockets') }
settings[:editor] = ask("Editor for notes? ") {|q| q.default = Settings.get(:editor) || 'vim' }
hr
say("saving settings to : #{Settings.path}")
Settings.settings = settings
h1('Done', :yellow)
end

def init(pocket_name)

end

def find(pocket_name, note_name)

end

def edit(pocket_name, note_name)
end

def push(pocket_name)
end

def pull(pocket_name)

end

def h1(text, color = :red)
say("<%= color('#{text}', :#{color}) %>")
end

def hr(color = :magenta)
say("<%= color('-' * 40, :#{color}) %>")
end
end
end
end
4 changes: 4 additions & 0 deletions lib/purse/pocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def initialize(path)
@path = File.expand_path(path)
end

def init(root_path, pocket_name)

end

def find(name)
Purse.check_for_parameter('name', name)
note = notes.find {|note| note.name == name }
Expand Down

0 comments on commit c7c9611

Please sign in to comment.