Skip to content

Commit

Permalink
feat: enable subdomain command in service group (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxck authored Mar 16, 2024
1 parent 3753fef commit 33a8382
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 112 deletions.
1 change: 1 addition & 0 deletions src/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ func serviceCmd() *cmdBuilder.Cmd {
AddChildrenCmd(serviceStartCmd()).
AddChildrenCmd(serviceStopCmd()).
AddChildrenCmd(servicePushCmd()).
AddChildrenCmd(serviceEnableSubdomainCmd()).
AddChildrenCmd(serviceDeployCmd())
}
55 changes: 55 additions & 0 deletions src/cmd/serviceEnableSubdomain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"context"

"github.com/zeropsio/zcli/src/cmd/scope"
"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/uxHelpers"
"github.com/zeropsio/zerops-go/dto/input/path"

"github.com/zeropsio/zcli/src/i18n"
)

func serviceEnableSubdomainCmd() *cmdBuilder.Cmd {
return cmdBuilder.NewCmd().
Use("enable-subdomain").
Short(i18n.T(i18n.CmdServiceEnableSubdomain)).
ScopeLevel(scope.Service).
Arg(scope.ServiceArgName, cmdBuilder.OptionalArg()).
HelpFlag(i18n.T(i18n.ServiceEnableSubdomainHelp)).
LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error {
enableSubdomainResponse, err := cmdData.RestApiClient.PutServiceStackEnableSubdomainAccess(
ctx,
path.ServiceStackId{
Id: cmdData.Service.ID,
},
)
if err != nil {
return err
}

responseOutput, err := enableSubdomainResponse.Output()
if err != nil {
return err
}

processId := responseOutput.Id

err = uxHelpers.ProcessCheckWithSpinner(
ctx,
cmdData.UxBlocks,
[]uxHelpers.Process{{
F: uxHelpers.CheckZeropsProcess(processId, cmdData.RestApiClient),
RunningMessage: i18n.T(i18n.ServiceEnablingSubdomain),
ErrorMessageMessage: i18n.T(i18n.ServiceEnablingSubdomain),
SuccessMessage: i18n.T(i18n.ServiceEnabledSubdomain),
}},
)
if err != nil {
return err
}

return nil
})
}
116 changes: 60 additions & 56 deletions src/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,54 @@ package i18n

var en = map[string]string{
// help
LoginHelp: "the login command.",
ProjectHelp: "the project command.",
ProjectListHelp: "the project list command.",
ScopeHelp: "the scope command.",
ScopeProjectHelp: "the scope project command.",
ScopeResetHelp: "the scope reset command.",
ProjectDeleteHelp: "the project delete command.",
ProjectImportHelp: "the project import command.",
ProjectServiceImportHelp: "the project service import command.",
ServiceHelp: "the service command.",
ServiceStartHelp: "the service start command.",
ServiceStopHelp: "the service stop command.",
ServiceDeleteHelp: "the service delete command.",
ServiceLogHelp: "the service log command.",
ServiceDeployHelp: "the service deploy command.",
ServiceListHelp: "the service list command.",
ServicePushHelp: "the service push command.",
StatusShowDebugLogsHelp: "the status show debug logs command.",
VersionHelp: "the version command.",
VpnHelp: "the vpn command.",
VpnUpHelp: "the vpn up command.",
VpnDownHelp: "the vpn down command.",
LoginHelp: "the login command.",
ProjectHelp: "the project command.",
ProjectListHelp: "the project list command.",
ScopeHelp: "the scope command.",
ScopeProjectHelp: "the scope project command.",
ScopeResetHelp: "the scope reset command.",
ProjectDeleteHelp: "the project delete command.",
ProjectImportHelp: "the project import command.",
ProjectServiceImportHelp: "the project service import command.",
ServiceHelp: "the service command.",
ServiceStartHelp: "the service start command.",
ServiceStopHelp: "the enable Zerops subdomain command.",
ServiceDeleteHelp: "the service delete command.",
ServiceLogHelp: "the service log command.",
ServiceDeployHelp: "the service deploy command.",
ServiceListHelp: "the service list command.",
ServicePushHelp: "the service push command.",
ServiceEnableSubdomainHelp: "the service stop command.",
StatusShowDebugLogsHelp: "the status show debug logs command.",
VersionHelp: "the version command.",
VpnHelp: "the vpn command.",
VpnUpHelp: "the vpn up command.",
VpnDownHelp: "the vpn down command.",

// cmd short
CmdDeployDesc: "Deploys your application to Zerops.",
CmdPushDesc: "Builds your application in Zerops and deploys it.",
CmdLogin: "Logs you into Zerops. Use a generated Zerops token or your login e-mail and password.",
CmdStatusShowDebugLogs: "Shows zCLI debug logs.",
CmdVersion: "Shows the current zCLI version.",
CmdProject: "Project commands group.",
CmdService: "Zerops service commands group.",
CmdProjectList: "Lists all projects.",
CmdScope: "Scope commands group",
CmdScopeProject: "Sets the scope for project. All commands that require project ID will use the selected one.",
CmdScopeReset: "Resets the scope for project and service.",
CmdProjectDelete: "Deletes a project and all of its services.",
CmdProjectImport: "Creates a new project with one or more services.",
CmdServiceList: "Lists all services in the project.",
CmdServiceImport: "Creates one or more Zerops services in an existing project.",
CmdServiceStart: "Starts the Zerops service.",
CmdServiceStop: "Stops the Zerops service.",
CmdServiceDelete: "Deletes the Zerops service.",
CmdServiceLog: "Get service runtime or build log to stdout.",
CmdVpn: "VPN commands group",
CmdVpnUp: "Connects to the Zerops VPN.",
CmdVpnDown: "Disconnects from the Zerops VPN.",
CmdDeployDesc: "Deploys your application to Zerops.",
CmdPushDesc: "Builds your application in Zerops and deploys it.",
CmdLogin: "Logs you into Zerops. Use a generated Zerops token or your login e-mail and password.",
CmdStatusShowDebugLogs: "Shows zCLI debug logs.",
CmdVersion: "Shows the current zCLI version.",
CmdProject: "Project commands group.",
CmdService: "Zerops service commands group.",
CmdProjectList: "Lists all projects.",
CmdScope: "Scope commands group",
CmdScopeProject: "Sets the scope for project. All commands that require project ID will use the selected one.",
CmdScopeReset: "Resets the scope for project and service.",
CmdProjectDelete: "Deletes a project and all of its services.",
CmdProjectImport: "Creates a new project with one or more services.",
CmdServiceList: "Lists all services in the project.",
CmdServiceImport: "Creates one or more Zerops services in an existing project.",
CmdServiceStart: "Starts the Zerops service.",
CmdServiceStop: "Stops the Zerops service.",
CmdServiceDelete: "Deletes the Zerops service.",
CmdServiceLog: "Get service runtime or build log to stdout.",
CmdServiceEnableSubdomain: "Enables access through Zerops subdomain.",
CmdVpn: "VPN commands group",
CmdVpnUp: "Connects to the Zerops VPN.",
CmdVpnDown: "Disconnects from the Zerops VPN.",

// cmd long
CmdProjectImportLong: "Creates a new project with one or more services according to the definition in the import YAML file.",
Expand Down Expand Up @@ -107,18 +109,20 @@ var en = map[string]string{
CoreServices: "Core services activation started",

// project + service
ProjectDeleteConfirm: "Project %s will be deleted? \n Are you sure?",
ServiceDeleteConfirm: "Service %s will be deleted? \n Are you sure?",
ProjectDeleting: "Project is being deleted",
ProjectDeleted: "Project was deleted",
ServiceStarting: "Service is being started",
ServiceStarted: "Service was started",
ServiceStopping: "Service is being stopped",
ServiceStopped: "Service was stopped",
ServiceDeleting: "Service is being deleted",
ServiceDeleted: "Service was deleted",
ProjectImported: "project imported",
ServiceImported: "service(s) imported",
ProjectDeleteConfirm: "Project %s will be deleted? \n Are you sure?",
ServiceDeleteConfirm: "Service %s will be deleted? \n Are you sure?",
ProjectDeleting: "Project is being deleted",
ProjectDeleted: "Project was deleted",
ServiceStarting: "Service is being started",
ServiceStarted: "Service was started",
ServiceStopping: "Service is being stopped",
ServiceStopped: "Service was stopped",
ServiceDeleting: "Service is being deleted",
ServiceDeleted: "Service was deleted",
ProjectImported: "project imported",
ServiceImported: "service(s) imported",
ServiceEnablingSubdomain: "enabling subdomain access",
ServiceEnabledSubdomain: "subdomain access enabled",

// service logs
LogLimitInvalid: "Invalid --limit value. Allowed interval is <1;1000>",
Expand Down
116 changes: 60 additions & 56 deletions src/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,54 @@ func T(textConst string, args ...interface{}) string {

const (
// help
LoginHelp = "LoginHelp"
ProjectHelp = "ProjectHelp"
ProjectListHelp = "ProjectListHelp"
ScopeHelp = "ScopeHelp"
ScopeProjectHelp = "ScopeProjectHelp"
ScopeResetHelp = "ScopeResetHelp"
ProjectDeleteHelp = "ProjectDeleteHelp"
ProjectImportHelp = "ProjectImportHelp"
ProjectServiceImportHelp = "ProjectServiceImportHelp"
ServiceHelp = "ServiceHelp"
ServiceStartHelp = "ServiceStartHelp"
ServiceStopHelp = "ServiceStopHelp"
ServiceDeleteHelp = "ServiceDeleteHelp"
ServiceLogHelp = "ServiceLogHelp"
ServiceDeployHelp = "ServiceDeployHelp"
ServiceListHelp = "ServiceListHelp"
ServicePushHelp = "ServicePushHelp"
StatusShowDebugLogsHelp = "StatusShowDebugLogsHelp"
VersionHelp = "VersionHelp"
VpnHelp = "VpnHelp"
VpnUpHelp = "VpnUpHelp"
VpnDownHelp = "VpnDownHelp"
LoginHelp = "LoginHelp"
ProjectHelp = "ProjectHelp"
ProjectListHelp = "ProjectListHelp"
ScopeHelp = "ScopeHelp"
ScopeProjectHelp = "ScopeProjectHelp"
ScopeResetHelp = "ScopeResetHelp"
ProjectDeleteHelp = "ProjectDeleteHelp"
ProjectImportHelp = "ProjectImportHelp"
ProjectServiceImportHelp = "ProjectServiceImportHelp"
ServiceHelp = "ServiceHelp"
ServiceStartHelp = "ServiceStartHelp"
ServiceStopHelp = "ServiceStopHelp"
ServiceDeleteHelp = "ServiceDeleteHelp"
ServiceLogHelp = "ServiceLogHelp"
ServiceDeployHelp = "ServiceDeployHelp"
ServiceListHelp = "ServiceListHelp"
ServicePushHelp = "ServicePushHelp"
ServiceEnableSubdomainHelp = "ServiceEnableSubdomainHelp"
StatusShowDebugLogsHelp = "StatusShowDebugLogsHelp"
VersionHelp = "VersionHelp"
VpnHelp = "VpnHelp"
VpnUpHelp = "VpnUpHelp"
VpnDownHelp = "VpnDownHelp"

// cmd short
CmdDeployDesc = "CmdDeployDesc"
CmdPushDesc = "CmdPushDesc"
CmdLogin = "CmdLogin"
CmdStatusShowDebugLogs = "CmdStatusShowDebugLogs"
CmdVersion = "CmdVersion"
CmdProject = "CmdProject"
CmdService = "CmdService"
CmdProjectList = "CmdProjectList"
CmdScope = "CmdScope"
CmdScopeProject = "CmdScopeProject"
CmdScopeReset = "CmdScopeReset"
CmdProjectDelete = "CmdProjectDelete"
CmdProjectImport = "CmdProjectImport"
CmdServiceList = "CmdServiceList"
CmdServiceImport = "CmdServiceImport"
CmdServiceStart = "CmdServiceStart"
CmdServiceStop = "CmdServiceStop"
CmdServiceDelete = "CmdServiceDelete"
CmdServiceLog = "CmdServiceLog"
CmdVpn = "CmdVpn"
CmdVpnUp = "CmdVpnUp"
CmdVpnDown = "CmdVpnDown"
CmdDeployDesc = "CmdDeployDesc"
CmdPushDesc = "CmdPushDesc"
CmdLogin = "CmdLogin"
CmdStatusShowDebugLogs = "CmdStatusShowDebugLogs"
CmdVersion = "CmdVersion"
CmdProject = "CmdProject"
CmdService = "CmdService"
CmdProjectList = "CmdProjectList"
CmdScope = "CmdScope"
CmdScopeProject = "CmdScopeProject"
CmdScopeReset = "CmdScopeReset"
CmdProjectDelete = "CmdProjectDelete"
CmdProjectImport = "CmdProjectImport"
CmdServiceList = "CmdServiceList"
CmdServiceImport = "CmdServiceImport"
CmdServiceStart = "CmdServiceStart"
CmdServiceStop = "CmdServiceStop"
CmdServiceDelete = "CmdServiceDelete"
CmdServiceLog = "CmdServiceLog"
CmdServiceEnableSubdomain = "CmdServiceEnableSubdomain"
CmdVpn = "CmdVpn"
CmdVpnUp = "CmdVpnUp"
CmdVpnDown = "CmdVpnDown"

// cmd long
CmdProjectImportLong = "CmdProjectImportLong"
Expand Down Expand Up @@ -120,18 +122,20 @@ const (
CoreServices = "CoreServices"

// project + service
ProjectDeleteConfirm = "ProjectDeleteConfirm"
ServiceDeleteConfirm = "ServiceDeleteConfirm"
ProjectDeleting = "ProjectDeleting"
ProjectDeleted = "ProjectDeleted"
ServiceStarting = "ServiceStarting"
ServiceStarted = "ServiceStarted"
ServiceStopping = "ServiceStopping"
ServiceStopped = "ServiceStopped"
ServiceDeleting = "ServiceDeleting"
ServiceDeleted = "ServiceDeleted"
ProjectImported = "ProjectImported"
ServiceImported = "ServiceImported"
ProjectDeleteConfirm = "ProjectDeleteConfirm"
ServiceDeleteConfirm = "ServiceDeleteConfirm"
ProjectDeleting = "ProjectDeleting"
ProjectDeleted = "ProjectDeleted"
ServiceStarting = "ServiceStarting"
ServiceStarted = "ServiceStarted"
ServiceStopping = "ServiceStopping"
ServiceStopped = "ServiceStopped"
ServiceEnablingSubdomain = "ServiceEnablingSubdomain"
ServiceEnabledSubdomain = "ServiceEnabledSubdomain"
ServiceDeleting = "ServiceDeleting"
ServiceDeleted = "ServiceDeleted"
ProjectImported = "ProjectImported"
ServiceImported = "ServiceImported"

// service logs
LogLimitInvalid = "LogLimitInvalid"
Expand Down

0 comments on commit 33a8382

Please sign in to comment.