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.
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 11
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
51
52
53
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 51
def self.help
"cp SOURCE_FILE WORKSPACE_NAME:/DESTINATION/PATH"
end
|
Instance Method Details
#build_package ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 43
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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 23
def run
FaaStRuby::CLI.error("You can't upload static files larger than 5MB. If you need to upload large files, please reach out to us on Slack at https://faastruby.io/slack") if source_file_too_big?
destination_url = URI.escape("#{FaaStRuby.workspace_host_for(@workspace_name)}/#{@relative_path}")
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
|
#source_file_too_big? ⇒ Boolean
39
40
41
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 39
def source_file_too_big?
File.size(@source_file) > 5242880 end
|
#usage ⇒ Object
55
56
57
58
|
# File 'lib/faastruby/cli/commands/workspace/cp.rb', line 55
def usage
puts "\n# Deploy static file SOURCE_FILE to workspace path /DESTINATION/PATH.\n"
puts "\nUsage: faastruby #{self.class.help}\n\n"
end
|