This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an executable that prints the status of all threads managed by …
…Titan ('titan status' on the terminal)
- Loading branch information
1 parent
90dc3a2
commit fb55749
Showing
7 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
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
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,4 @@ | ||
#!/usr/bin/env ruby | ||
require "titan" | ||
|
||
Titan::Cli.start |
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,6 @@ | ||
require "titan/version" | ||
|
||
module Titan | ||
autoload :Cli, "titan/cli" | ||
autoload :Thread, "titan/thread" | ||
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "thor" | ||
|
||
module Titan | ||
class Cli < Thor | ||
include Thor::Actions | ||
|
||
def initialize(*) | ||
super | ||
@shell = Thor::Shell::Basic.new | ||
end | ||
|
||
desc "help", "Describes available command line options" | ||
def help | ||
@shell.say "The following methods are available through typing `titan method_name`" | ||
@shell.say "" | ||
available_methods = [ | ||
["method_name", "description"], | ||
["", ""], | ||
["help", "Prints this page and describes available methods"], | ||
["status", "Prints the status of all threads managed by Titan"], | ||
["version", "Prints the currently installed version"] | ||
] | ||
@shell.print_table(available_methods) | ||
end | ||
|
||
desc "status", "Prints the status of all threads managed by Titan" | ||
def status | ||
table_header = ["id", "pid", "status"] | ||
threads = Titan::Thread.all.each_value.collect { |thread| | ||
[thread.id.to_s, thread.pid.to_s, thread.alive? ? "alive" : "dead"] | ||
} | ||
@shell.print_table(threads.unshift(table_header)) unless threads.empty? | ||
end | ||
|
||
desc "version", "Prints the currently installed version" | ||
def version | ||
@shell.say Titan::VERSION | ||
end | ||
map %w(--version -v) => :version | ||
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,3 +1,3 @@ | ||
module Titan | ||
VERSION = "0.2.1" | ||
VERSION = "0.3.0.dev" | ||
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
|
||
describe Titan::Cli do | ||
before(:each) do | ||
@shell = mock(Thor::Shell::Basic, :print_table => nil, :say => nil) | ||
Thor::Shell::Basic.stub!(:new).and_return(@shell) | ||
@cli = Titan::Cli.new | ||
end | ||
|
||
describe "#help" do | ||
it "should print the methods as a table" do | ||
@shell.should_receive(:print_table) | ||
@cli.help | ||
end | ||
end | ||
|
||
describe "#status" do | ||
it "should load all threads" do | ||
Titan::Thread.should_receive(:all).and_return({}) | ||
@cli.status | ||
end | ||
|
||
context "given there are threads available" do | ||
before(:each) do | ||
Titan::Thread.stub!(:all).and_return({'test' => Titan::Thread.new(:id => 'test')}) | ||
end | ||
|
||
it "should print the threads as a table" do | ||
@shell.should_receive(:print_table) | ||
@cli.status | ||
end | ||
end | ||
|
||
context "given there are no threads available" do | ||
before(:each) do | ||
Titan::Thread.stub!(:all).and_return({}) | ||
end | ||
|
||
it "should not print the threads as a table" do | ||
@shell.should_not_receive(:print_table) | ||
@cli.status | ||
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