Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

CLI #1

Merged
merged 2 commits into from

1 participant

daniel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2013
  1. Implemented cli using thor

    authored
This page is out of date. Refresh to see the latest.
4 Rakefile
View
@@ -1,5 +1,5 @@
require 'rake/extensiontask'
-require 'rake/testtask'
+#require 'rake/testtask'
require 'yard'
$:.unshift(File.dirname(__FILE__) + '/lib')
@@ -24,5 +24,5 @@ task :tag do
end
YARD::Rake::YardocTask.new do |t|
- t.files = ['lib/ctdb.rb', 'ext/**/*.c']
+ t.files = ['lib/**/*.rb', 'ext/**/*.c']
end
5 bin/ctdb
View
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+require 'ctdb'
+require 'ctdb/cli'
+
+CT::CLI.start
3  ctdb.gemspec
View
@@ -13,8 +13,11 @@ Gem::Specification.new do |s|
s.files = Dir['lib/**/*.rb'] +
Dir['ext/ctdb_ext/*.{h,c,rb}']
+ s.executables << 'ctdb'
s.test_files = Dir['test/*.rb']
s.extensions = [ 'ext/ctdb_ext/extconf.rb' ]
+
+ s.add_dependency "thor"
end
4 ext/ctdb_ext/ct_table.c
View
@@ -259,8 +259,8 @@ rb_ct_table_get_create_mode(VALUE self)
ct_table *table;
GetCTTable(self, table);
-
- return FIX2INT(ctdbGetTableCreateMode(table->handle));
+
+ return INT2FIX(ctdbGetTableCreateMode(table->handle));
}
/*
65 lib/ctdb/cli.rb
View
@@ -0,0 +1,65 @@
+require 'thor'
+require 'yaml'
+
+module CT
+ class CLI < Thor
+ method_option :server, :type => :string, :default => "FAIRCOMS"
+ method_option :username, :type => :string, :default => ""
+ method_option :password, :type => :string, :default => ""
+
+ desc "schema", "Print a table's schema definition"
+ def schema(table_path)
+ logon(options['server'], options['username'], options['password'])
+
+ table = CT::Table.new(@session)
+ table.path = File.dirname(table_path)
+ table.open(File.basename(table_path), CT::OPEN_READONLY)
+
+ puts "There are %d fields in %s/%s" %
+ [ table.field_count, table.path, table.name ]
+ puts
+ puts " Field Name Field Type Len"
+ puts " ---------------- ---------- ---"
+ table.fields.each do |field|
+ puts "%3d) %-20s %-10s %4d" %
+ [ field.number, field.name, field.human_type, field.length ]
+ end
+ puts
+ puts " There are %d index(s)" % table.indecies.count
+ puts
+ table.indecies.each do |index|
+ puts " Index Name - %s" % index.name
+ puts index.allow_dups? ? " Dups Allowed" : " No Dups Allowed"
+ index.segments.each_with_index do |segment, i|
+ if i == 0
+ puts segment.absolute_byte_offset? ? " Field Offset" : " Byte Offset"
+ puts
+ puts " Seg Field Name Len Seg Mode"
+ puts " ------------------ --- ---------------"
+ end
+ length = segment.field.length
+ length -= 1 if segment.absolute_byte_offset?
+ puts " %-20s %4d %s" %
+ [ segment.field_name, segment.field.length, segment.human_mode ]
+ end
+ puts
+ end
+
+ table.close
+ ensure
+ logout
+ end
+
+ private
+
+ def logon(server, username, password)
+ @session = CT::Session.new(CT::SESSION_CTREE)
+ @session.logon(server, username, password)
+ end
+
+ def logout
+ @session.logout
+ end
+
+ end
+end
2  lib/ctdb/index.rb
View
@@ -39,7 +39,7 @@ def to_h
{ name: self.name,
key_type: self.human_key_type,
allow_dups: self.allow_dups?,
- allow_null: self.allow_null?,
+ #allow_null: self.allow_null?,
key_length: self.key_length,
segments: self.segments.collect { |segment| segment.to_h } }
end
Something went wrong with that request. Please try again.