-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a 'debug' command that replaces ./bin/console
This may as well be a part of the tool as it could be useful to be able to jump into a console for various reasons once the tool is installed. It's not just useful during development.
- Loading branch information
Showing
6 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
require "zz/help" | ||
require "zz/path" | ||
|
||
require "zz/commands/debug" | ||
require "zz/commands/provision" | ||
|
||
require "zz/base" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module ZZ | ||
COMMANDS = [Provision] | ||
COMMANDS = [Debug, Provision] | ||
|
||
def self.execute(args) | ||
command_name = args.shift | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module ZZ | ||
module Debug | ||
class << self | ||
def execute(args) | ||
run_pry | ||
rescue LoadError | ||
run_irb | ||
end | ||
|
||
def run_pry | ||
require "pry" | ||
ZZ.pry | ||
end | ||
|
||
def run_irb | ||
require "irb" | ||
IRB.start | ||
end | ||
|
||
def name | ||
"debug" | ||
end | ||
|
||
def summary | ||
"runs an introspective debugger for zz" | ||
end | ||
|
||
def description | ||
[ | ||
"This command starts a pry session in the context of the tuzz", | ||
"automation tool and falls back to irb if pry is unavailable. It is", | ||
"useful for debugging problems with the tool and for calling library", | ||
"code in ways that weren't anticipated... or were they?", | ||
].join("\n ") | ||
end | ||
|
||
def options | ||
[] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require "rspec" | ||
require "irb" | ||
require "pry" | ||
require "fileutils" | ||
require "zz" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
RSpec.describe ZZ::Debug do | ||
it "provides useful information about itself" do | ||
expect(subject.name).to eq("debug") | ||
expect(subject.summary).to eq("runs an introspective debugger for zz") | ||
expect(subject.description).to match(/starts a pry session/) | ||
end | ||
|
||
it "runs pry" do | ||
expect(ZZ).to receive(:pry) | ||
subject.execute([]) | ||
end | ||
|
||
it "falls back to irb if pry is unavailable" do | ||
allow(subject).to receive(:run_pry).and_raise(LoadError) | ||
|
||
expect(IRB).to receive(:start) | ||
subject.execute([]) | ||
end | ||
end |