-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patharchiveEnvironment.go
More file actions
63 lines (54 loc) · 1.61 KB
/
archiveEnvironment.go
File metadata and controls
63 lines (54 loc) · 1.61 KB
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
package main
import (
"fmt"
"io"
"net/http"
"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)
const archiveEnvironmentShortDesc = `Archive a Kosli environment.`
const archiveEnvironmentLongDesc = archiveEnvironmentShortDesc + `
The environment will no longer be visible in list of environments, data is still stored in the database.
`
const archiveEnvironmentExample = `
# archive a Kosli environment:
kosli archive environment yourEnvironmentName \
--api-token yourAPIToken \
--org yourOrgName
`
type ArchiveEnvironmentPayload struct {
}
func newArchiveEnvironmentCmd(out io.Writer) *cobra.Command {
payload := new(ArchiveEnvironmentPayload)
cmd := &cobra.Command{
Use: "environment ENVIRONMENT-NAME",
Short: archiveEnvironmentShortDesc,
Long: archiveEnvironmentLongDesc,
Example: archiveEnvironmentExample,
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
err := RequireGlobalFlags(global, []string{"Org", "ApiToken"})
if err != nil {
return ErrorBeforePrintingUsage(cmd, err.Error())
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
url := fmt.Sprintf("%s/api/v2/environments/%s/%s/archive", global.Host, global.Org, args[0])
reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: payload,
DryRun: global.DryRun,
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && global.DryRun == "false" {
logger.Info("environment %s was archived", args[0])
}
return err
},
}
addDryRunFlag(cmd)
return cmd
}