-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
117 lines (92 loc) · 2.67 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
copycat is an environment file manager.
The program allows for ".env" files to be uploaded, this creates an
"environment". With an environment created, files can be uploaded, and
associated with that given environment. Files can then later be downloaded.
Any S3-compliant system (i.e., Amazon S3, MinIO, CloudFlare R2) can be used to
store the files, provided you can create an access key and secret for a
specified bucket.
CopyCat now also supports profiles. By default, the "default" profile is used.
Profiles allow for multiple configurations to be created, and later referenced.
Usage:
copycat [-profile <name>] <command>
The commands are:
help
Prints out the help message
list
Lists the environments which have been uploaded
download <environment>
Downloads a given .env file corresponding to the environment name
upload <environment>
Uploads a given .env file
files <sub-command>
See below.
As of now, copycat expects the file ".env" to exist, and that is the file it
will automatically upload. Once an environment is created
(using the upload command), CopyCat will also allow files to be uploaded. File
management is handled via the following sub-commands:
help
Prints out the files help message
<environment> list
Lists the files available in a given environment
<environment> upload <file name> [upload name]
Uploads the specified file under the given environment
<environment> download <file name> [download name]
Downloads the specified file, allowing for it's name to be
overwritten
*/
package main
import (
"flag"
"fmt"
"os"
)
const version string = "v1.5.0"
var VersionHost string
var VersionLog string
// Main function routine, serves as main entry point.
func main() {
if len(os.Args) < 2 {
fmt.Println(Warn("At least one argument is needed"))
help(false)
os.Exit(1)
}
// Get default profile, unless profile is explicitly defined.
profilePtr := flag.String("profile", "default", "profile to be used")
flag.Parse()
os.Setenv("COPYCAT_PROFILE", *profilePtr)
// Load environment variables
os.Setenv("VERSION_LOG", VersionLog)
os.Setenv("VERSION_HOST", VersionHost)
args := flag.Args()
// Case on passed arguments
switch args[0] {
case "configure":
configure()
case "list":
list(true)
case "download":
requireArgs(args, 2, true, false)
name := args[1]
download(name)
case "upload":
requireArgs(args, 2, true, false)
name := args[1]
upload(name)
case "files":
files(args[1:])
case "help":
help(false)
case "version":
fmt.Println(OK(version))
case "version-clean":
fmt.Println(version)
case "update":
update()
case "reset":
reset()
default:
fmt.Println(Warn("Not a valid option."))
help(false)
}
}