Skip to content

Commit

Permalink
Uses the current directory by default
Browse files Browse the repository at this point in the history
`whereto organize .` can now be achieved with `whereto organize`
  • Loading branch information
jutonz committed Sep 7, 2015
1 parent bc1b59c commit 0f68d8c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
/.bundle/
/.yardoc
/Gemfile.lock
Expand Down
6 changes: 4 additions & 2 deletions bin/whereto
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env ruby
require 'gli'
require_relative '../lib/where_to'
require_relative '../lib/where_to_cli/helpers'

include GLI::App
include WhereToCLI

PROMPT_DESCRIPTORS = Hash.new do |hash, key|
hash[key] = "a #{key}"
Expand Down Expand Up @@ -55,13 +57,13 @@ command :organize do |cmd|

cmd.action do |global_options, options, args|
puts ''
location = args[0]
raise "The location '#{location}' does not exist" unless File.exist? location
location = Helpers::check_location!(args.first)

@options = options

Dir.chdir location
files = Dir.glob "*#{options[:ext]}"
raise WhereTo::NoFilesError.new(options[:ext], location) if files.none?
puts "I found the following files:"
files.each { |file| puts file }
puts ''
Expand Down
12 changes: 11 additions & 1 deletion lib/where_to.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
require 'date'

# Require all the libraries!
Dir[File.dirname(__FILE__) + "/where_to/**/*.rb"].each { |f| require_relative f }
require_files = %w(
configuration
episode_formatter
location
locator
tvdb
version
error/no_files_error
).each do |require_file|
require_relative "where_to/#{require_file}"
end

module WhereTo
class << self
Expand Down
7 changes: 7 additions & 0 deletions lib/where_to/error/no_files_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module WhereTo
class NoFilesError < RuntimeError
def initialize(extension, location)
super("I couldn't find any files with the extension #{extension} in #{location}")
end
end
end
2 changes: 1 addition & 1 deletion lib/where_to/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module WhereTo
VERSION = "1.0.0"
VERSION = "1.0.1"
end
9 changes: 9 additions & 0 deletions lib/where_to_cli/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module WhereToCLI
module Helpers
def self.check_location!(location)
return '.' if location.nil?
raise "The location '#{location}' does not exist" unless File.exist? location
location
end
end
end
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
require 'where_to/locator'
require 'where_to/episode_formatter'
require 'where_to/configuration'
require 'where_to/tvdb'
require 'where_to/tvdb'

require 'where_to_cli/helpers'

25 changes: 25 additions & 0 deletions spec/where_to_cli/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

describe WhereToCLI::Helpers do

describe ".check_location!" do
it "returns . if no location is given" do
expect(WhereToCLI::Helpers.check_location!(nil)).to eql '.'
end

it "raises if the location does not exist" do
expect(File).to receive(:exist?).with('/some/location') { false }

expect {
WhereToCLI::Helpers.check_location!('/some/location')
}.to raise_error "The location '/some/location' does not exist"
end

it "returns a valid location" do
expect(File).to receive(:exist?).with('/some/location') { true }

expect(WhereToCLI::Helpers.check_location!('/some/location'))
.to eql '/some/location'
end
end
end

0 comments on commit 0f68d8c

Please sign in to comment.