Class: Migr8::Application
- Inherits:
-
Object
- Object
- Migr8::Application
- Defined in:
- lib/migr8.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.main(args = nil) ⇒ Object
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 |
# File 'lib/migr8.rb', line 1910 def self.main(args=nil) #; [!cy0yo] uses ARGV when args is not passed. args = ARGV if args.nil? app = self.new begin status = app.run(args) #; [!maomq] command-option error is cached and not raised. rescue Util::CommandOptionError => ex script = File.basename($0) $stderr << "ERROR[#{script}] #{ex.message}\n" status = 1 #; rescue Migr8Error => ex script = File.basename($0) $stderr << "ERROR[#{script}] #{ex}\n" status = 1 end #; [!t0udo] returns status code (0: ok, 1: error). return status end |
Instance Method Details
#run(args) ⇒ Object
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 |
# File 'lib/migr8.rb', line 1859 def run(args) parser = new_cmdopt_parser() = parser.parse(args) # may raise CommandOptionError #; [!dcggy] sets Migr8::DEBUG=true when '-d' or '--debug' specified. if ['debug'] ::Migr8.DEBUG = true end #; [!ktlay] prints help message and exit when '-h' or '--help' specified. if ['help'] $stdout << self.usage(parser) return 0 end #; [!n0ubh] prints version string and exit when '-v' or '--version' specified. if ['version'] $stdout << RELEASE << "\n" return 0 end #; action_name = args.shift || default_action_name() action_class = Actions::Action.find_by_name(action_name) or raise Util::CommandOptionError.new("#{action_name}: unknown action.") action_obj = action_class.new action_opts = action_obj.parse(args) if action_opts['help'] puts action_obj.usage else action_obj.run(action_opts, args) end #; [!saisg] returns 0 as status code when succeeded. return 0 end |
#usage(parser = nil) ⇒ Object
1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 |
# File 'lib/migr8.rb', line 1891 def usage(parser=nil) parser ||= new_cmdopt_parser() script = File.basename($0) s = "" s << "#{script} -- database schema version management tool\n" s << "\n" s << "Usage: #{script} [global-options] [action [options] [...]]\n" s << parser.usage(20, ' ') s << "\n" s << "Actions: (default: #{default_action_name()})\n" Migr8::Actions::Action.subclasses.each do |action_class| s << action_class.new.short_usage() end s << "\n" s << "(ATTENTION!! Run '#{script} readme' at first if you don't know #{script} well.)\n" s << "\n" return s end |