Class: FaaStRuby::Command::Workspace::CP
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) ⇒ CP
Returns a new instance of CP.
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 10
def initialize(args)
@args = args
help
@source_file = @args.shift
@workspace_name, @relative_path = @args.shift.split(':')
validate_command
@package_file = Tempfile.new('package')
@tmpdir = Dir.mktmpdir("package")
load_credentials
end
|
Class Method Details
.help ⇒ Object
47
48
49
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 47
def self.help
"cp SOURCE_FILE WORKSPACE_NAME:/DESTINATION/PATH"
end
|
Instance Method Details
#build_package ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 38
def build_package
FileUtils.cp @source_file, @tmpdir
output_file = @package_file.path
FaaStRuby::Package.new(@tmpdir, output_file).build
@package_file.close
output_file
end
|
#run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 22
def run
destination_url = "#{FaaStRuby.workspace_host_for(@workspace_name)}/#{@relative_path}"
spinner = say("[#{@source_file}] Copying file to '#{destination_url}'...", quiet: true)
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
package = build_package
workspace.upload_file(package, relative_path: @relative_path)
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
puts "* [#{@source_file}] Upload OK".green
puts "* [#{@source_file}] URL: #{destination_url}".green
ensure
FileUtils.remove_entry @tmpdir
@package_file.unlink
end
|
#usage ⇒ Object
51
52
53
54
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 51
def usage
puts "\n# Deploy static file SOURCE_FILE to workspace path /DESTINATION/PATH.\n"
puts "\nUsage: faastruby #{self.class.help}\n\n"
end
|