Module: JSONtoDB::CLI

Defined in:
lib/jsontodb/cli.rb

Overview

This module handles the command-line interface for JSONtoDB

Class Method Summary collapse

Class Method Details

.authentication_credentials(user = nil, pass = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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_cliObject



36
37
38
39
40
41
42
43
44
# 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

.passObject



32
33
34
# File 'lib/jsontodb/cli.rb', line 32

def pass
  @pass
end

.tokenize_command(input) ⇒ Object



46
47
48
49
50
# File 'lib/jsontodb/cli.rb', line 46

def tokenize_command(input)
  input.split(/\s(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/)
       .select { |s| !s.empty? }
       .map { |s| s.gsub(/(^ +)|( +$)|(^["']+)|(["']+$)/, '') }
end

.userObject



28
29
30
# File 'lib/jsontodb/cli.rb', line 28

def user
  @user
end