Class: BuildTool::Commands::Shell

Inherits:
SubCommands show all
Defined in:
lib/build-tool/commands.rb

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from SubCommands

#add_command, #complete_arguments, #complete_command, #do_complete, #execute, #get_command, #help_commands, #initialize, #load_commands, #show_help

Methods inherited from Base

#<=>, #applicable?, #cleanup_after_vcs_access, #complete_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #do_execute, #each_option, #error, #execute, #fullname, #info, #initialize, #log?, #setup_options, #show_help, #skip_command, #summarize, #teardown_command, #trace, #usage, #verbose, #warn

Methods included from HelpText

#cmdalias, #description, included, #long_description

Constructor Details

This class inherits a constructor from BuildTool::Commands::SubCommands

Instance Method Details

#cliObject Also known as: default_command



961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'lib/build-tool/commands.rb', line 961

def cli
    require 'readline'
    Readline.completion_proc = method(:complete_readline)

    while true

        begin

            line = Readline.readline('> ', true)

            return 0 if line.nil?

            # Ignore whitespace lines
            next if Shellwords.shellwords( line ).length == 0

            # Remove duplicate or empty lines from history
            if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
                Readline::HISTORY.pop
            end

            # Split the line like bash would do it
            execute Shellwords.shellwords( line )

        rescue BuildTool::Error => e
            error( e.message )
            verbose( e.backtrace.join("\n") )
        rescue StandardError => e
            error( e.message )
            error( e.backtrace.join("\n") )
        rescue Interrupt => e
            info( "Use CTRL-D for exit!" )
        end

    end

    return 0
end

#initialize_optionsObject



901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
# File 'lib/build-tool/commands.rb', line 901

def initialize_options
    options.banner = "Usage: #{name} [OPTIONS]... COMMAND [COMMAND OPTIONS]..."

    options.separator ''
    options.separator "Options"

    options.on( "-v", "--verbose", "Enable verbose output" ) do
        Logging.appenders['stdout'].level = [ Logging.appenders['stdout'].level - 1, 0 ].max()
    end

    options.on( nil, "--dry-run", "Enable dry run." ) do
        $noop = true
    end

    options.on( "-V", "--version", "Print version information." ) do
        show_version
    end

    options.on( "--ionice", "Set io io niceness to idle (3)." ) { |n|

        pid = Process.pid()
        system( "ionice -p #{pid} -c 3" )
        cur = `ionice -p #{pid}`
        info( 'Process priority (io niceness): %s' % cur )
    }

    options.on( "--nice N", "Set niceness to N." ) { |n|
        if not /^[0-9]+$/.match( n )
            raise OptionParser::ParseError.new( 'value "%s" is not a number' %  n )
        end

        # Set the priority
        Process.setpriority( Process::PRIO_PROCESS, 0, n.to_i() )

        # Check if it worked.
        cur = Process.getpriority( Process::PRIO_PROCESS, 0 )
        if n.to_i() != cur
            warn( 'Process priority (niceness): %d (%d was given)' % [ cur, n ] )
        else
            info( 'Process priority (niceness): %d' % [ cur ] )
        end
    }

    options.on( "--debug-db", "Debug the database." ) do
        Logging.logger['ActiveRecord'].level = :debug
    end

    super()
end

#nameObject



897
898
899
# File 'lib/build-tool/commands.rb', line 897

def name
    return Pathname.new($0).basename.to_s
end

#setup_commandObject



951
952
953
954
# File 'lib/build-tool/commands.rb', line 951

def setup_command
    # And the commands require all that database related stuff.
    load_commands( Application::instance.application_root.join( "lib/build-tool/commands" ), BuildTool::Commands )
end

#show_versionObject



956
957
958
959
# File 'lib/build-tool/commands.rb', line 956

def show_version
    @skip_command = true
    info( "#{name()}: Version #{BuildTool::VERSION}" )
end