Skip to content

Commit

Permalink
user flag is mandatory for the list files command
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjiangshu committed Sep 4, 2024
1 parent c011fd6 commit f087a02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
9 changes: 1 addition & 8 deletions sda-admin/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ func ListUsers(api_uri, token string) error {

// ListFiles returns all files
func ListFiles(api_uri, token, username string) error {
var url string
response, err := helpers.GetResponseBody(fmt.Sprintf("%s/users/%s/files", api_uri, username), token)

if username == "" {
url = api_uri + "/files"
} else {
url = fmt.Sprintf("%s/users/%s/files", api_uri, username)
}

response, err := helpers.GetResponseBody(url, token)
if err != nil {
return err
}
Expand Down
22 changes: 15 additions & 7 deletions sda-admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var usage = `USAGE:
Commands:
list users List all users
list files [-user USERNAME] List all files associated to the token, optionally for a specified user
list files -user USERNAME List all files for a specified user
file ingest -filepath FILEPATH -user USERNAME
Trigger ingestion of the given file
file accession -filepath FILEPATH -user USERNAME -accession-id accessionID
Expand All @@ -50,11 +50,11 @@ List Users:
List all users in the system.
List Files:
Usage: sda-admin list files [-user USERNAME]
List all files, optionally for a specific user.
Usage: sda-admin list files -user USERNAME
List all files for a specified user.
Options:
-user USERNAME (For list files) List files owned by the specified username.
-user USERNAME (For list files) List files owned by the specified user
Use 'sda-admin help list <command>' for information on a specific list command.
`
Expand All @@ -69,11 +69,11 @@ func listUsersUsage() {
}

func listFilesUsage() {
usageText := `Usage: sda-admin list files [-user USERNAME]
List all files, optionally for a specific user
usageText := `Usage: sda-admin list files -user USERNAME
List all files for a specified user.
Options:
-user USERNAME List files owned by the specified username.
-user USERNAME List files owned by the specified user
`
fmt.Println(usageText)
}
Expand Down Expand Up @@ -308,6 +308,14 @@ func handleListFilesCommand() {
var username string
listFilesCmd.StringVar(&username, "user", "", "Filter files by username")
listFilesCmd.Parse(flag.Args()[2:])

// Check if the -user flag was provided
if username == "" {
fmt.Println("Error: the -user flag is required.")
listFilesUsage()
os.Exit(1)
}

checkToken(token)
err := list.ListFiles(api_uri, token, username)
if err != nil {
Expand Down

0 comments on commit f087a02

Please sign in to comment.