Skip to content

Commit 7e1d0bd

Browse files
committed
feat: add parse_arch func, testing passed
1 parent 4bc6331 commit 7e1d0bd

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

lib/rootfs/distro/ubuntu/arch.rb

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module RootFS
44
module Distro
55
module Ubuntu
6+
extend self
7+
68
ARCH = %w[
79
amd64
810
arm64
@@ -11,6 +13,20 @@ module Ubuntu
1113
riscv64
1214
s390x
1315
].freeze
16+
17+
def parse_arch(any)
18+
err_msg = "Valid Ubuntu arch: #{ARCH}"
19+
20+
puts err_msg unless any
21+
22+
str = any.to_s
23+
puts err_msg if str.empty?
24+
25+
ARCH.each do |arch|
26+
return { arch: arch } if str.include?(arch)
27+
end
28+
puts err_msg
29+
end
1430
end
1531
end
1632
end

lib/rootfs/distro/ubuntu/edition.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def parse_edition(any)
5050
puts err_msg if str.empty?
5151

5252
EDITION.each do |edition|
53-
return { edition: edition } if any.include?(edition)
53+
return { edition: edition } if str.include?(edition)
5454
end
5555
puts err_msg
5656
end

lib/rootfs/distro/ubuntu/file.rb

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require_relative "../../http"
44
require_relative "../../data"
5+
require_relative "arch"
56

67
module RootFS
78
module Distro
@@ -46,6 +47,11 @@ def files_of(*argv, daily: false, **opts)
4647
arch = argv[2] || opts[:arch] || "amd64"
4748
devkit = argv[3] || opts[:devkit]
4849

50+
hash = RootFS::Distro::Ubuntu.parse_arch(arch)
51+
return unless hash
52+
53+
arch = hash[:arch]
54+
4955
keywords = [edition, arch]
5056
ignores = []
5157

lib/rootfs/distro/ubuntu/file_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class MyClass
1515
p u.files_of("server", 20.04)
1616
p u.files_of("base", 20.04)
1717
p u.files_of("base", "focal")
18+
p u.files_of("base", 20.04, "riscv64")
19+
p u.files_of("base", "focal", "loongarch")
1820
p u.files_of("cloud", "focal")
1921
p u.files_of("cloud", 22.04)
2022
p u.files_of("minimal", 22.04)

0 commit comments

Comments
 (0)