From dbb2063ef5ea5b4cac274dd43d794736fc733490 Mon Sep 17 00:00:00 2001 From: Joshua Moody Date: Mon, 30 Mar 2015 17:47:25 +0200 Subject: [PATCH] Add cli/errors --- bin/run-loop | 3 ++- lib/run_loop/cli/cli.rb | 3 +-- lib/run_loop/cli/errors.rb | 11 +++++++++++ lib/run_loop/cli/instruments.rb | 1 + spec/lib/bin/errors_spec.rb | 21 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 lib/run_loop/cli/errors.rb create mode 100644 spec/lib/bin/errors_spec.rb diff --git a/bin/run-loop b/bin/run-loop index 3a24379f..d6a1f425 100755 --- a/bin/run-loop +++ b/bin/run-loop @@ -1,11 +1,12 @@ #!/usr/bin/env ruby require 'run_loop/cli/cli' +require 'run_loop/cli/errors' require 'run_loop/environment' begin RunLoop::CLI::Tool.start exit 0 -rescue RunLoop::ValidationError, Thor::RequiredArgumentMissingError, Thor::UndefinedCommandError => e +rescue RunLoop::CLI::ValidationError, Thor::RequiredArgumentMissingError, Thor::UndefinedCommandError => e puts e.message exit 64 rescue Thor::Error => e diff --git a/lib/run_loop/cli/cli.rb b/lib/run_loop/cli/cli.rb index 89a8d794..6539c700 100644 --- a/lib/run_loop/cli/cli.rb +++ b/lib/run_loop/cli/cli.rb @@ -1,5 +1,6 @@ require 'thor' require 'run_loop' +require 'run_loop/cli/errors' require 'run_loop/cli/instruments' trap 'SIGINT' do @@ -8,8 +9,6 @@ end module RunLoop - class ValidationError < Thor::InvocationError - end module CLI diff --git a/lib/run_loop/cli/errors.rb b/lib/run_loop/cli/errors.rb new file mode 100644 index 00000000..0b78bc16 --- /dev/null +++ b/lib/run_loop/cli/errors.rb @@ -0,0 +1,11 @@ +require 'thor' + +module RunLoop + module CLI + class ValidationError < Thor::InvocationError + end + + class NotImplementedError < Thor::InvocationError + end + end +end diff --git a/lib/run_loop/cli/instruments.rb b/lib/run_loop/cli/instruments.rb index a5ec1483..15379bba 100644 --- a/lib/run_loop/cli/instruments.rb +++ b/lib/run_loop/cli/instruments.rb @@ -1,5 +1,6 @@ require 'thor' require 'run_loop' +require 'run_loop/cli/errors' module RunLoop module CLI diff --git a/spec/lib/bin/errors_spec.rb b/spec/lib/bin/errors_spec.rb new file mode 100644 index 00000000..cdcaba80 --- /dev/null +++ b/spec/lib/bin/errors_spec.rb @@ -0,0 +1,21 @@ +require 'run_loop/cli/errors' + +describe RunLoop::CLI::ValidationError do + + it 'can be used to raise an error' do + expect { + raise RunLoop::CLI::ValidationError, 'Hey!' + }.to raise_error + end + +end + +describe RunLoop::CLI::NotImplementedError do + + it 'can be used to raise an error' do + expect { + raise RunLoop::CLI::NotImplementedError, 'Hey!' + }.to raise_error + end + +end