module JSONtoDB::CLI
This module handles the command-line interface for JSONtoDB
Attributes
pass[RW]
user[RW]
Public Instance Methods
authentication_credentials(user = nil, pass = nil)
click to toggle source
# File lib/jsontodb/cli.rb, line 11 def authentication_credentials(user = nil, pass = nil) if user.nil? || pass.nil? puts 'USER AUTHENTICATION' puts '===================' puts print 'Username: ' @user = STDIN.gets.chomp print 'Password: ' @pass = STDIN.noecho(&:gets).chomp puts puts else @user = user @pass = pass end end
continuous_cli()
click to toggle source
# File lib/jsontodb/cli.rb, line 36 def continuous_cli print 'jsontodb> ' input = STDIN.gets.chomp while input != 'exit' JSONtoDB::Processor.run_command(tokenize_command(input), @user, @pass) print 'jsontodb> ' input = STDIN.gets.chomp end end
tokenize_command(input)
click to toggle source
# File lib/jsontodb/cli.rb, line 46 def tokenize_command(input) input.split(/\s(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/) .select { |s| !s.empty? } .map { |s| s.gsub(/(^ +)|( +$)|(^["']+)|(["']+$)/, '') } end