bin/birstcl in Birst_Command-0.3.0 vs bin/birstcl in Birst_Command-0.4.0

- old
+ new

@@ -4,10 +4,28 @@ require "optparse" module BirstCL extend self + def run + set_options + + if @options[:version] + puts "Birst_Command Version: #{Birst_Command::VERSION}" + exit + end + + if @options[:encrypt_password] + encrypt_password(@options[:encrypt_password]) + end + + if @options[:command] + read_config_file + execute_command + end + end + def set_options @options = {} OptionParser.new do |opts| opts.banner = "Usage: birstcl -c <COMMAND> -a <ARGUMENTS>" @@ -24,10 +42,15 @@ opts.on("-h","--help", "Show this message") do puts opts exit end + @options[:encrypt_password] = nil + opts.on("-e","--encrypt_password <PASSWORD>","Generates an encrypted version of PASSWORD that needs to be placed in ~/.birstcl") do |opt| + @options[:encrypt_password] = opt + end + @options[:command] = nil opts.on("-c","--command <COMMAND>","COMMAND is the snake_case Birst web API command") do |opt| @options[:command] = opt end @@ -55,25 +78,27 @@ @options[:read_cookie_full_path] = nil opts.on("-r","--read_cookie_file <COOKIE FILE>", "Path to cookie file to read") do |opt| @options[:read_cookie_full_path] = opt end - end.parse! - - if @options[:version] - puts "Birst_Command Version: #{Birst_Command::VERSION}" - exit - end end def read_config_file Birst_Command::Config.read_config(@options[:config_full_path]) end + def encrypt_password(password) + Birst_Command::Password.generate_keys(verbose: true) + puts <<-EOF.unindent + ... + Use this encrypted password in your .birstcl file: "#{Birst_Command::Password.encrypt(password)}" + EOF + end + def write_cookie_file(file_full_path) return nil if file_full_path.nil? File.open(file_full_path, 'w') {|f| f.write(Marshal.dump(@session_cookie)) } end @@ -98,8 +123,6 @@ puts "#{JSON.pretty_generate output}" write_cookie_file(@options[:write_cookie_full_path]) end end -BirstCL.set_options -BirstCL.read_config_file -BirstCL.execute_command +BirstCL.run