Class: FaaStRuby::Command::Workspace::Create

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/faastruby/cli/commands/workspace/create.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file

Constructor Details

#initialize(args) ⇒ Create

Returns a new instance of Create.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/faastruby/cli/commands/workspace/create.rb', line 7

def initialize(args)
  @args = args
  help
  @missing_args = []
  FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
  @workspace_name = @args.shift
  validate_name
  @base_dir = "./#{@workspace_name}"
  parse_options
  load_credentials
end

Class Method Details

.helpObject



35
36
37
# File 'lib/faastruby/cli/commands/workspace/create.rb', line 35

def self.help
  "create-workspace WORKSPACE_NAME [ARGS]"
end

Instance Method Details

#run(create_directory: true, exit_on_error: true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/faastruby/cli/commands/workspace/create.rb', line 19

def run(create_directory: true, exit_on_error: true)
  unless @options['skip_creation']
    spinner = spin("Setting up workspace '#{@workspace_name}'...")
    workspace = FaaStRuby::Workspace.create(name: @workspace_name, email: @options['email'])
    if workspace.errors.any?
      spinner.error if exit_on_error
      FaaStRuby::CLI.error(workspace.errors) if exit_on_error
      spinner.success
      return false
    end
    spinner.success
  end
  create_dir if @options['create_local_dir'] && create_directory && !dir_exists?
  true
end

#usageObject



39
40
41
42
43
44
# File 'lib/faastruby/cli/commands/workspace/create.rb', line 39

def usage
  puts "\nUsage: faastruby #{self.class.help}"
  puts %(
--create-local-dir    # Create a local directory with the workspace name.
  )
end