Class: OSDN::CLI::Command::Relfile
Instance Attribute Summary
Attributes inherited from Base
#credential, #format, #logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from FrsBase
#run
Methods inherited from Base
#credential_path, #initialize, #load_credential, #load_variables, #set_client_token, #set_credential, #update_token, #update_variables, #write_credential, #write_variables
Class Method Details
.description ⇒ Object
19
20
21
|
# File 'lib/osdn/cli/command/relfile.rb', line 19
def self.description
"Manipulate frs files of project"
end
|
Instance Method Details
#create ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/osdn/cli/command/relfile.rb', line 67
def create
filename = ARGV.shift
if !filename
logger.fatal "Target filename is missing."
help
return
end
file = Pathname('.') + filename
logger.debug "Calculating digest for #{file}..."
digests = {
sha256: hexdigest(Digest::SHA256, file),
sha1: hexdigest(Digest::SHA1, file),
md5: hexdigest(Digest::MD5, file),
}
fio = file.open
logger.level <= Logger::INFO and
OSDN::CLI._show_progress = true
logger.info "Starting upload #{file}..."
f = api.create_release_file target_proj, target_package, target_release, fio, visibility: @visibility
fio.close
OSDN::CLI._show_progress = false
if digests.find { |type, dig| dig != f.send("digest_#{type}") }
logger.error "File digests are mismatch! Upload file #{file} may be broken! Please check."
else
logger.info "Upload complete."
end
puts format_file(f)
end
|
#delete ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/osdn/cli/command/relfile.rb', line 112
def delete
target_id = ARGV.shift
if !target_id
logger.fatal "Target file ID is missing."
help
return
end
f = api.delete_release_file target_proj, target_package, target_release, target_id
logger.info "file #{target_id} has been deleted."
end
|
#help ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/osdn/cli/command/relfile.rb', line 6
def help
puts "#{$0} relfile [opts] [list]"
puts "#{$0} relfile [opts] create <target-file>"
puts "#{$0} relfile [opts] update <numeric-file-id>"
puts "#{$0} relfile [opts] delete <numeric-file-id>"
puts "Options:"
puts " -f --format=<pretty|json> Set output format"
puts " -p --project=<project> Target project (numeric id or name)"
puts " --package=<project> Target package (numeric id)"
puts " --release=<project> Target release (numeric id)"
puts " -v --visibility=<public|private|hidden>"
end
|
#list ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/osdn/cli/command/relfile.rb', line 55
def list
release = api.get_release target_proj, target_package, target_release
list = release.files
if format == 'json'
puts list.map{|i| i.to_hash}.to_json
else
list.each do |f|
puts format_file(f)
end
end
end
|
#process_options ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/osdn/cli/command/relfile.rb', line 23
def process_options
opts = GetoptLong.new(
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
[ '--project', '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '--package', GetoptLong::REQUIRED_ARGUMENT ],
[ '--release', GetoptLong::REQUIRED_ARGUMENT ],
[ '--visibility', '-v', GetoptLong::REQUIRED_ARGUMENT ],
)
opts.each do |opt, arg|
case opt
when '--format'
arg == 'json' and
self.format = arg
when '--project'
arg.empty? or
@target_proj = arg
when '--package'
arg.empty? or
@target_package = arg
when '--release'
arg.empty? or
@target_release = arg
when '--visibility'
unless %w(public private hidden).member?(arg)
logger.fatal "Invalid visibility status: #{arg}"
exit
end
@visibility = arg
end
end
end
|
#update ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/osdn/cli/command/relfile.rb', line 96
def update
target_id = ARGV.shift
if !target_id
logger.fatal "Target file ID is missing."
help
return
end
if @visibility.nil?
logger.fatal "Visibility status is missing. Use '-v <public|private|hidden>'."
return
end
f = api.update_release_file target_proj, target_package, target_release, target_id, visibility: @visibility
logger.info "file #{target_id} has been updated."
puts format_file(f)
end
|