Class: Spark::CLI
- Inherits:
-
Object
- Object
- Spark::CLI
- Includes:
- Commander::Methods
- Defined in:
- lib/spark/cli.rb
Instance Method Summary collapse
-
#run ⇒ Object
IRB_HISTORY_FILE = File.join(Dir.home, ‘.irb_spark_history’) IRB_HISTORY_SIZE = 100.
Instance Method Details
#run ⇒ Object
IRB_HISTORY_FILE = File.join(Dir.home, ‘.irb_spark_history’) IRB_HISTORY_SIZE = 100
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/spark/cli.rb', line 19 def run program :name, 'RubySpark' program :version, Spark::VERSION program :description, 'Ruby wrapper for Spark' global_option('-d', '--debug', 'Logging message to stdout'){ $DEBUG = true } default_command :help # Build --------------------------------------------------------------- command :build do |c| c.syntax = 'build [options]' c.description = 'Build spark and gem extensions' c.option '--hadoop-version STRING', String, 'Version of hadoop which will assembled with the Spark' c.option '--spark-core-version STRING', String, 'Version of Spark core' c.option '--spark-version STRING', String, 'Version of Spark' c.option '--scala-version STRING', String, 'Version of Scala' c.option '--target STRING', String, 'Directory where Spark will be stored' c.option '--only-ext', 'Build only extension for RubySpark' c.action do |args, | Spark::Build.build(.__hash__) puts puts 'Everything is OK' end end alias_command :install, :build # Shell ----------------------------------------------------------------- command :shell do |c| c.syntax = 'shell [options]' c.description = 'Start ruby shell for spark' c.option '--target STRING', String, 'Directory where Spark is stored' c.option '--properties-file STRING', String, 'Path to a file from which to load extra properties' c.option '--[no-]start', 'Start Spark immediately' c.option '--[no-]logger', 'Enable/disable logger (default: enable)' c.action do |args, | .default start: true, logger: true Spark.load_lib(.target) Spark.logger.disable unless .logger Spark.config do set_app_name 'RubySpark' end Spark.config.from_file(.properties_file) if .start # Load Java and Spark Spark.start $sc = Spark.context Spark.print_logo('Spark context is loaded as $sc') else Spark.print_logo('You can start Spark with Spark.start') end # Load Pry require 'pry' Pry.start end end # # IRB ------------------------------------------------------------------- # command :irb do |c| # c.syntax = 'irb [options]' # c.description = 'Start ruby shell for spark' # c.option '--spark-home STRING', String, 'Directory where Spark is stored' # c.option '--[no-]start', 'Start Spark immediately' # c.option '--[no-]logger', 'Enable/disable logger (default: enable)' # # c.action do |args, options| # options.default start: true, logger: true # # Spark.load_lib(options.spark_home) # Spark::Logger.disable unless options.logger # # Spark.config do # set_app_name 'Pry RubySpark' # end # # if options.start # # Load Java and Spark # Spark.start # $sc = Spark.context # # Spark.print_logo('Spark context is loaded as $sc') # else # Spark.print_logo('You can start Spark with Spark.start') # end # # # Load IRB # require 'irb' # require 'irb/completion' # require 'irb/ext/save-history' # # begin # file = File.expand_path(IRB_HISTORY_FILE) # if File.exists?(file) # lines = IO.readlines(file).collect { |line| line.chomp } # Readline::HISTORY.push(*lines) # end # Kernel.at_exit do # lines = Readline::HISTORY.to_a.reverse.uniq.reverse # lines = lines[-IRB_HISTORY_SIZE, IRB_HISTORY_SIZE] if lines.nitems > IRB_HISTORY_SIZE # File.open(IRB_HISTORY_FILE, File::WRONLY | File::CREAT | File::TRUNC) { |io| io.puts lines.join("\n") } # end # rescue # end # # ARGV.clear # Clear Thor ARGV, otherwise IRB will parse it # ARGV.concat ['--readline', '--prompt-mode', 'simple'] # IRB.start # end # end # Home ------------------------------------------------------------------ command :home do |c| c.action do |args, | puts Spark.home exit(0) end end # Ruby spark jar -------------------------------------------------------- command :ruby_spark_jar do |c| c.action do |args, | puts Spark.ruby_spark_jar exit(0) end end run! end |