Class: BetterAuth::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/better_auth/cli.rb,
lib/better_auth/cli/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.10.0"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdout:, stderr:) ⇒ CLI

Returns a new instance of CLI.



29
30
31
32
33
# File 'lib/better_auth/cli.rb', line 29

def initialize(argv, stdout:, stderr:)
  @argv = argv.dup
  @stdout = stdout
  @stderr = stderr
end

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



15
16
17
# File 'lib/better_auth/cli.rb', line 15

def configuration
  @configuration
end

Class Method Details

.configure(value = nil) ⇒ Object



17
18
19
# File 'lib/better_auth/cli.rb', line 17

def configure(value = nil)
  @configuration = block_given? ? yield : value
end

.run(argv = ARGV, stdout: $stdout, stderr: $stderr) ⇒ Object



21
22
23
24
25
26
# File 'lib/better_auth/cli.rb', line 21

def run(argv = ARGV, stdout: $stdout, stderr: $stderr)
  new(argv, stdout: stdout, stderr: stderr).run
rescue Error, BetterAuth::SQLMigration::UnsupportedAdapterError, BetterAuth::Error, OptionParser::ParseError => error
  stderr.puts error.message
  1
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/better_auth/cli.rb', line 35

def run
  command = argv.shift
  case command
  when "generate"
    generate(argv)
  when "migrate"
    migrate(argv)
  when "doctor"
    doctor(argv)
  when "mongo"
    mongo(argv)
  when "-h", "--help", "help", nil
    stdout.puts usage
    0
  else
    raise Error, "Unknown command: #{command}"
  end
end