Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Added an executable that prints the status of all threads managed by …
Browse files Browse the repository at this point in the history
…Titan ('titan status' on the terminal)
  • Loading branch information
flippingbits committed Dec 10, 2010
1 parent 90dc3a2 commit fb55749
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## dev

- Features

* Added an executable that prints the status of all threads managed by Titan ('titan status' on the terminal)

- Bug fixes

* Fixed "warning: don't put space before argument parentheses" in thread.rb at line 124
Expand Down
4 changes: 4 additions & 0 deletions bin/titan
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require "titan"

Titan::Cli.start
1 change: 1 addition & 0 deletions lib/titan.rb
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
41 changes: 41 additions & 0 deletions lib/titan/cli.rb
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
2 changes: 1 addition & 1 deletion lib/titan/version.rb
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
45 changes: 45 additions & 0 deletions spec/titan/cli_spec.rb
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
3 changes: 3 additions & 0 deletions titan.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ Gem::Specification.new do |s|
s.email = %q{info@stefan-sprenger.com}
s.extra_rdoc_files = ["LICENSE", "README.md"]
s.files = Dir.glob("{lib}/**/*") + %w(LICENSE README.md CHANGELOG.md)
s.executables = ["titan"]
s.homepage = %q{http://github.com/flippingbits/titan}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{Helps you creating and managing daemon threads with Ruby.}

s.add_dependency("thor")

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
Expand Down

0 comments on commit fb55749

Please sign in to comment.