You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(storage/import): extract content type mapping to package level
- Move supportedContentTypes map to package level for reusability
- Add getSupportedExtensionsText() to list all supported file extensions
- Add getSupportedContentTypesText() to list all supported content types
- Update --source-location help to show supported extensions dynamically
- Update --content-type help to show supported types dynamically
- Simplify getContentType() to use the package-level map
- Help text now automatically reflects all supported formats
// getSupportedContentTypesText returns a formatted string of supported content types
68
+
funcgetSupportedContentTypesText() string {
69
+
seen:=make(map[string]bool)
70
+
vartypes []string
71
+
for_, ct:=rangesupportedContentTypes {
72
+
if!seen[ct] {
73
+
types=append(types, ct)
74
+
seen[ct] =true
75
+
}
76
+
}
77
+
// Sort for consistent output
78
+
fori:=0; i<len(types); i++ {
79
+
forj:=i+1; j<len(types); j++ {
80
+
iftypes[i] >types[j] {
81
+
types[i], types[j] =types[j], types[i]
82
+
}
83
+
}
84
+
}
85
+
varresultstring
86
+
fori, ct:=rangetypes {
87
+
ifi>0 {
88
+
result+=", "
89
+
}
90
+
result+=ct
91
+
}
92
+
returnresult
93
+
}
94
+
28
95
// ImportCommand creates the "storage import" command
29
96
funcImportCommand() commands.Command {
30
97
return&importCommand{
@@ -70,9 +137,9 @@ type importCommand struct {
70
137
// InitCommand implements Command.InitCommand
71
138
func (s*importCommand) InitCommand() {
72
139
flagSet:=&pflag.FlagSet{}
73
-
flagSet.StringVar(&s.sourceLocation, "source-location", "", "Location of the source of the import. Can be a file or a URL.")
140
+
flagSet.StringVar(&s.sourceLocation, "source-location", "", fmt.Sprintf("Location of the source of the import. Can be a file or a URL. Supported file extensions: %s", getSupportedExtensionsText()))
74
141
flagSet.StringVar(&s.existingStorageUUIDOrName, "storage", "", "Import to an existing storage. Storage must be large enough and must be undetached or the server where the storage is attached must be in shutdown state.")
75
-
flagSet.StringVar(&s.contentType, "content-type", "", "Content type of the file being imported. If not specified, it will be automatically detected based on file extension. Supported types: application/gzip, application/x-xz, application/x-tar, application/x-bzip2, application/x-7z-compressed, application/zip, application/octet-stream")
142
+
flagSet.StringVar(&s.contentType, "content-type", "", fmt.Sprintf("Content type of the file being imported. If not specified, it will be automatically detected based on file extension. Supported types: %s", getSupportedContentTypesText()))
76
143
config.AddToggleFlag(flagSet, &s.noWait, "no-wait", false, "When importing from remote url, do not wait until the import finishes or storage is in online state. If set, command will exit after import process has been initialized.")
77
144
config.AddToggleFlag(flagSet, &s.wait, "wait", false, "Wait for storage to be in online state before returning.")
0 commit comments