122 lines
3.3 KiB
Go
122 lines
3.3 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*
|
|
* This work is published and licensed under a Creative Commons
|
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
|
*
|
|
* Distribution of this work is permitted, but commercial use and
|
|
* modifications are strictly prohibited.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
|
var subCmd = &cobra.Command{
|
|
Use: "file",
|
|
Short: "File operation",
|
|
}
|
|
// PutFile
|
|
var putFileCmd = &cobra.Command{
|
|
Use: "put",
|
|
Short: "Put file to storage",
|
|
Run: util.PutFile,
|
|
}
|
|
putFileCmd.Flags().StringVarP(&util.putFileParams.Username, "username", "u", "", "Username")
|
|
putFileCmd.Flags().StringVarP(&util.putFileParams.Password, "password", "p", "", "Password")
|
|
putFileCmd.Flags().StringVarP(&util.putFileParams.Source, "src", "s", "", "Source path")
|
|
putFileCmd.Flags().StringVarP(&util.putFileParams.Dest, "dest", "d", "", "Desctination path")
|
|
|
|
subCmd.AddCommand(putFileCmd)
|
|
|
|
// GetFile
|
|
var getFileCmd = &cobra.Command{
|
|
Use: "get",
|
|
Short: "Get file from storage",
|
|
Run: util.GetFile,
|
|
}
|
|
getFileCmd.Flags().StringVarP(&util.getFileParams.Username, "username", "u", "", "Username")
|
|
getFileCmd.Flags().StringVarP(&util.getFileParams.Password, "password", "p", "", "Password")
|
|
getFileCmd.Flags().StringVarP(&util.getFileParams.Source, "src", "s", "", "Source path")
|
|
getFileCmd.Flags().StringVarP(&util.getFileParams.Dest, "dest", "d", "", "Desctination path")
|
|
|
|
subCmd.AddCommand(getFileCmd)
|
|
|
|
// FileExists
|
|
var fileExistsCmd = &cobra.Command{
|
|
Use: "exist",
|
|
Short: "Check file into storage",
|
|
Run: util.FileExists,
|
|
}
|
|
fileExistsCmd.Flags().StringVarP(&util.fileExistsParams.Username, "username", "u", "", "Username")
|
|
fileExistsCmd.Flags().StringVarP(&util.fileExistsParams.Password, "password", "p", "", "Password")
|
|
fileExistsCmd.Flags().StringVarP(&util.fileExistsParams.Filepath, "path", "d", "", "File path")
|
|
|
|
subCmd.AddCommand(fileExistsCmd)
|
|
|
|
// FileExists
|
|
var deleteFileCmd = &cobra.Command{
|
|
Use: "delete",
|
|
Short: "Delete file in storage",
|
|
Run: util.DeleteFile,
|
|
}
|
|
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Username, "username", "u", "", "Username")
|
|
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Password, "password", "p", "", "Password")
|
|
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Filepath, "path", "d", "", "File path")
|
|
|
|
subCmd.AddCommand(deleteFileCmd)
|
|
|
|
return subCmd
|
|
}
|
|
|
|
type FileUtil struct {
|
|
fileExistsParams FileExistsParams
|
|
putFileParams PutFileParams
|
|
getFileParams GetFileParams
|
|
deleteFileParams DeleteFileParams
|
|
}
|
|
|
|
// File exists
|
|
type FileExistsParams struct {
|
|
Filepath string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func (util *FileUtil) FileExists(cmd *cobra.Command, args []string) {
|
|
}
|
|
|
|
// Put file
|
|
type PutFileParams struct {
|
|
Source string
|
|
Dest string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func (util *FileUtil) PutFile(cmd *cobra.Command, args []string) {
|
|
}
|
|
|
|
// Get file
|
|
type GetFileParams struct {
|
|
Source string
|
|
Dest string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func (util *FileUtil) GetFile(cmd *cobra.Command, args []string) {
|
|
}
|
|
|
|
// Delete file
|
|
type DeleteFileParams struct {
|
|
Filepath string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func (util *FileUtil) DeleteFile(cmd *cobra.Command, args []string) {
|
|
}
|