-
Notifications
You must be signed in to change notification settings - Fork 1
/
asset.go
45 lines (36 loc) · 1.19 KB
/
asset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package pobj
import (
"fmt"
"github.com/charmbracelet/ssh"
"github.com/picosh/send/utils"
)
type AssetNames interface {
BucketName(sesh ssh.Session) (string, error)
ObjectName(sesh ssh.Session, entry *utils.FileEntry) (string, error)
PrintObjectName(sesh ssh.Session, entry *utils.FileEntry, bucketName string) (string, error)
}
type AssetNamesBasic struct{}
var _ AssetNames = &AssetNamesBasic{}
var _ AssetNames = (*AssetNamesBasic)(nil)
func (an *AssetNamesBasic) BucketName(sesh ssh.Session) (string, error) {
return sesh.User(), nil
}
func (an *AssetNamesBasic) ObjectName(sesh ssh.Session, entry *utils.FileEntry) (string, error) {
return entry.Filepath, nil
}
func (an *AssetNamesBasic) PrintObjectName(sesh ssh.Session, entry *utils.FileEntry, bucketName string) (string, error) {
objectName, err := an.ObjectName(sesh, entry)
if err != nil {
return "", err
}
return fmt.Sprintf("%s%s", bucketName, objectName), nil
}
type AssetNamesForceBucket struct {
*AssetNamesBasic
Name string
}
var _ AssetNames = &AssetNamesForceBucket{}
var _ AssetNames = (*AssetNamesForceBucket)(nil)
func (an *AssetNamesForceBucket) BucketName(sesh ssh.Session) (string, error) {
return an.Name, nil
}