Class: OSDN::CLI::Command::FrsMkdirs
- Inherits:
-
Base
- Object
- Base
- OSDN::CLI::Command::FrsMkdirs
show all
- Defined in:
- lib/osdn/cli/command/frs_mkdirs.rb
Instance Attribute Summary
Attributes inherited from Base
#credential, #format, #logger
Class Method Summary
collapse
Instance Method Summary
collapse
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
64
65
66
|
# File 'lib/osdn/cli/command/frs_mkdirs.rb', line 64
def self.description
"Make directory tree for current project release"
end
|
Instance Method Details
#help ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/osdn/cli/command/frs_mkdirs.rb', line 6
def help
puts "#{$0} frs_mkdirs [opts] [target_dir]"
puts "Options:"
puts " -p --project=<project> Target project (numeric id or name)"
end
|
#run ⇒ Object
14
15
16
17
18
19
20
21
22
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
54
55
56
57
58
59
60
61
62
|
# File 'lib/osdn/cli/command/frs_mkdirs.rb', line 14
def run
update_token
opts = GetoptLong.new(
[ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ],
[ '--project', '-p', GetoptLong::REQUIRED_ARGUMENT ],
)
opts.each do |opt, arg|
case opt
when '--project'
arg.empty? or
@target_proj = arg
end
end
proj_info = api.get_project target_proj
target_dir = Pathname.new(ARGV.shift || '.')
FileUtils.mkdir_p target_dir
update_variables target_dir, project: target_proj
logger.debug "Getting Package list..."
packages = api.list_packages target_proj
logger.debug "Making each package directory"
packages.each do |package|
pname = fsname(package.name)
if pname != package.name
logger.warn "Package name '#{package.name}' is not suitable for filesystem, using '#{pname}'."
end
logger.info "Making directory for package #{pname}"
pdir = target_dir + pname
FileUtils.mkdir_p(pdir)
update_variables pdir, package_id: package.id
package.releases.each do |release|
rname = fsname(release.name)
if rname != release.name
logger.warn "Release name '#{release.name}' is not suitable for filesystem, using '#{rname}'."
end
logger.info "Making directory for release #{rname}"
rdir = pdir + rname
if rdir.exist? && !rdir.directory?
logger.error "'#{rdir}' exists but it is not a directory. Please check and delete it."
next
end
FileUtils.mkdir_p(rdir)
update_variables rdir, release_id: release.id
end
end
end
|