sheldon 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3849dcc28716d5aafca1ee0dafda7347d12ae85
4
- data.tar.gz: e6a90dc5d6027d5f4e7114aecae52d5b14db2995
3
+ metadata.gz: 487c6c4147a1150abb17257433fcda2b6f6ad629
4
+ data.tar.gz: 53510c73fd4fda5290524726616714f012ccbb27
5
5
  SHA512:
6
- metadata.gz: fc98eca6fdbb01a0c384aa029620c0286764f36f3d3599ac3dcd9751b07b81eb9548ec108e3421adda50da998949af08942d15adb3ccd91d93a774a9f8d52577
7
- data.tar.gz: 58a7b7b0dddead7f6363b513198026bc7501d4f980c1d71ad38d5ac0d333aa9ccefbd8c78d55cad428239cb8efeaf07575b94c7aa25c5cbc166ce122ae9e06c4
6
+ metadata.gz: 84bf9a06bd954b774f95b1d8888fe6b271e7a5a2f09d178365720110d24ceea9fcf2734f32f3939359349e2687c7b3ecc07405b7578910d5d6cbf74a7494ab20
7
+ data.tar.gz: 0d21743a01c3495b37c257f7c5ad670eb7f754f15dd6d0a83ea3a35ee82c51b8097a8c6a805705947edf77e8ecc00c7750bce63901deb2f92e820a50f97c15a0
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "thor"
3
+ require "tty-prompt"
3
4
  require_relative "../lib/sheldon"
4
5
 
5
6
  module CLI
@@ -18,23 +19,23 @@ module CLI
18
19
  if sheldon.build(abs_build_path)
19
20
  announce("Built #{File.basename(rel_path_to_target)}")
20
21
  else
21
- say("Could not find any config_ files at #{abs_build_path}", :red)
22
+ prompt.error("Could not find any config_ files at #{abs_build_path}")
22
23
  end
23
24
  end
24
25
  end
25
26
 
26
27
  desc "forget recall_cue", "Remove file/folder from Sheldon's brain"
27
28
  def forget(recall_cue=nil)
28
- recall_cue ||= ask("Recall Cue For File/Folder")
29
+ recall_cue ||= cue_picker("What would you like to forget?")
29
30
  with_exception_handling { sheldon.forget(recall_cue) }
30
31
  announce("I've forgotten about #{recall_cue}. Let us never mention it again.")
31
32
  end
32
33
 
33
- desc "learn path", "Add a new file/folder to Sheldon's brain. Supply a recall_cue at runtime."
34
+ desc "learn path_to_target", "Add a new file/folder to Sheldon's brain. Supply a recall_cue at runtime."
34
35
  def learn(rel_path_to_target)
35
36
  abs_learn_path = File.expand_path(rel_path_to_target)
36
37
  default_cue = File.basename(rel_path_to_target)
37
- recall_cue = ask("Recall Cue For File/Folder", default: default_cue)
38
+ recall_cue = prompt.ask("Recall Cue For File/Folder", default: default_cue, required: true)
38
39
  with_exception_handling { sheldon.learn(recall_cue, abs_learn_path) }
39
40
  with_exception_handling { sheldon.recall(recall_cue) }
40
41
  end
@@ -42,21 +43,36 @@ module CLI
42
43
  desc "list", "List all recall cues known by Sheldon"
43
44
  def list
44
45
  sheldon.list_cues.each do |recall_cue|
45
- sheldon.recalled?(recall_cue) ? say(recall_cue, :green) : say(recall_cue, :red)
46
+ sheldon.recalled?(recall_cue) ? prompt.say(recall_cue, color: :green) : prompt.say(recall_cue, color: :red)
46
47
  end
47
48
  end
48
49
 
49
- desc "recall recall_cue", "Symlink a previously learnt file/directory to it's original location on the filesystem.\nUse `sheldon list` for available cues."
50
+ desc "open recall_cue", "Open your file/folder contents in your default editor"
51
+ def open(recall_cue=nil)
52
+ editor = ENV['EDITOR']
53
+ error_and_exit("Your system does not define a default editor. Please set $EDITOR and try again.") if editor.nil?
54
+
55
+ recall_cue ||= cue_picker("What would you like to open?")
56
+ error_and_exit("#{recall_cue} has not been recalled on this computer. Use `sheldon recall #{recall_cue}` and then try again.") unless sheldon.recalled?(recall_cue)
57
+
58
+ with_exception_handling do
59
+ memory_entry = sheldon.brain.memory.recall(recall_cue)
60
+ filepath = add_home(memory_entry[:filepath])
61
+ system("#{ENV['EDITOR']} '#{filepath}'")
62
+ end
63
+ end
64
+
65
+ desc "recall recall_cue", "Recall a previously learnt file/directory to it's original location on the filesystem.\nUse `sheldon list` for available cues."
50
66
  option :i, type: :boolean, desc: "Interactive mode - prompts Y/N for each available recall_cue"
51
67
 
52
68
  def recall(recall_cue=nil)
53
69
  if options[:i]
54
70
  sheldon.list_cues.each do |recall_cue|
55
- answer = ask("Recall #{recall_cue}? (Y/N)")
71
+ answer = prompt.yes?("Recall #{recall_cue}?")
56
72
  with_exception_handling { sheldon.recall(recall_cue) if answer.downcase == "y" }
57
73
  end
58
74
  else
59
- recall_cue ||= ask("Recall Cue For File/Folder")
75
+ recall_cue = cue_picker("What would you like to recall?")
60
76
  with_exception_handling { sheldon.recall(recall_cue) }
61
77
  end
62
78
 
@@ -65,16 +81,16 @@ module CLI
65
81
 
66
82
  desc "setup path_to_data_directory", "Setup Sheldon on this host, supplying the path that where Sheldon's data directory can be found, or should be created."
67
83
  def setup(rel_data_path=nil)
68
- rel_data_path ||= ask("Please supply location for new/existing data directory")
84
+ rel_data_path ||= prompt.ask("Please supply location for new/existing data directory", required: true)
69
85
  abs_data_path = File.expand_path(rel_data_path)
70
86
  with_exception_handling do
71
87
  sheldon = ::Sheldon.new(abs_data_path)
72
88
 
73
89
  if sheldon.brain.present?
74
- say("Using existing Sheldon database found at #{abs_data_path}.", :green)
90
+ prompt.ok("Using existing Sheldon database found at #{abs_data_path}.")
75
91
  else
76
92
  sheldon.setup!
77
- say("New Sheldon database created at #{abs_data_path}", :green)
93
+ prompt.ok("New Sheldon database created at #{abs_data_path}")
78
94
  end
79
95
 
80
96
  write_to_dotfile("data_directory", sheldon.brain.location)
@@ -93,6 +109,19 @@ module CLI
93
109
  puts logo + " Sheldon" + logo + " #{message}"
94
110
  end
95
111
 
112
+ def error_and_exit(message)
113
+ prompt.error(message)
114
+ exit!
115
+ end
116
+
117
+ def prompt
118
+ @prompt ||= TTY::Prompt.new(interrupt: :exit)
119
+ end
120
+
121
+ def cue_picker(message)
122
+ prompt.select(message, sheldon.list_cues, per_page: 20, filter: true)
123
+ end
124
+
96
125
  def read_from_dotfile(key)
97
126
  dotfile = YAML::Store.new(add_home(".sheldon"))
98
127
  dotfile.transaction { dotfile[key] }
@@ -104,7 +133,7 @@ module CLI
104
133
 
105
134
  def sheldon_data_dir
106
135
  sheldon_data_dir = read_from_dotfile("data_directory") || ENV['SHELDON_DATA_DIR']
107
- sheldon_data_dir || raise("No configuration found. Please run `sheldon setup`")
136
+ sheldon_data_dir || error_and_exit("No configuration found. Please run `sheldon setup`")
108
137
  end
109
138
 
110
139
  def with_exception_handling(&block)
@@ -113,7 +142,7 @@ module CLI
113
142
  if options[:debug]
114
143
  puts ([e.inspect] + e.backtrace).join("\n")
115
144
  else
116
- say(e.message + "\nUse --debug to print backtrace", :red)
145
+ prompt.error(e.message + "\nUse --debug to print backtrace")
117
146
  end
118
147
  exit!
119
148
  end
@@ -24,7 +24,7 @@ class Brain
24
24
  def learn(recall_cue, abs_learn_path)
25
25
  raise "recall cue cannot be empty." if recall_cue.strip.empty?
26
26
  raise "This cue has already been used." if has_cue?(recall_cue)
27
- raise "Unable to find a file or folder at #{abs_learn_path}" unless File.exists?(abs_learn_path)
27
+ raise "Unable to find a file or folder at #{abs_learn_path}" unless File.exist?(abs_learn_path)
28
28
 
29
29
  brain_path = brain_path_for_cue(recall_cue)
30
30
  FileUtils.mkdir_p(brain_path)
@@ -30,7 +30,7 @@ class Memory
30
30
  end
31
31
 
32
32
  def present?
33
- File.exists?(@database.path)
33
+ File.exist?(@database.path)
34
34
  end
35
35
 
36
36
  def save!
@@ -1,11 +1,11 @@
1
1
  require "fileutils"
2
2
 
3
3
  class Sheldon
4
- VERSION = "0.5.5".freeze
4
+ VERSION = "0.6.0".freeze
5
5
  attr_reader :brain, :builder
6
6
 
7
7
  def initialize(sheldon_data_dir)
8
- unless Dir.exists?(sheldon_data_dir)
8
+ unless Dir.exist?(sheldon_data_dir)
9
9
  raise MissingDataDirectoryException, "Directory #{sheldon_data_dir} does not exist."
10
10
  end
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheldon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-29 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement