-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upload get and list commands (#47)
This change adds the necessary API logic to get and list upload objects stored in the AWAT database. It also fixes some logging issues and updates dependencies.
- Loading branch information
1 parent
f76f70f
commit 4201c49
Showing
15 changed files
with
551 additions
and
825 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/mattermost/awat/model" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
uploadID = "upload-id" | ||
) | ||
|
||
func init() { | ||
uploadCmd.PersistentFlags().String(serverFlag, "http://localhost:8077", "The AWAT to communicate with") | ||
|
||
getUploadCmd.PersistentFlags().String(uploadID, "", "ID of the upload to get") | ||
getUploadCmd.MarkPersistentFlagRequired(uploadID) | ||
|
||
uploadCmd.AddCommand(getUploadCmd) | ||
uploadCmd.AddCommand(getUploadsCmd) | ||
} | ||
|
||
var uploadCmd = &cobra.Command{ | ||
Use: "upload", | ||
Short: "Commands for reviewing upload objects", | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
}, | ||
} | ||
|
||
var getUploadCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Fetch an upload from the AWAT", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
uploadID, _ := cmd.Flags().GetString(uploadID) | ||
|
||
server, _ := cmd.Flags().GetString(serverFlag) | ||
client := model.NewClient(server) | ||
|
||
upload, err := client.GetUpload(uploadID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return printJSON(upload) | ||
}, | ||
} | ||
|
||
var getUploadsCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all uploads from the AWAT", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
server, _ := cmd.Flags().GetString(serverFlag) | ||
client := model.NewClient(server) | ||
|
||
statuses, err := client.GetUploads() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return printJSON(statuses) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.