Skip to content

Commit

Permalink
chore: don't export funcs; rewrite docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
bvtujo committed Oct 4, 2023
1 parent 44e97b8 commit eafbce3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
28 changes: 15 additions & 13 deletions internal/pkg/cli/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ const (
jobWkldType = "job"
)

// FilterItemsByStrings is a generic function to return the subset of wantedStrings that exists in possibleItems.
// filterItemsByStrings is a generic function to return the subset of wantedStrings that exists in possibleItems.
// stringFunc is a method to convert the generic item type (T) to a string; for example, one can convert a struct of type
// *config.Workload to a string by passing
//
// func(w *config.Workload) string { return w.Name }.
//
// Likewise, FilterItemsByStrings can work on a list of strings by returning the unmodified item:
// Likewise, filterItemsByStrings can work on a list of strings by returning the unmodified item:
//
// FilterItemsByStrings(wantedStrings, stringSlice2, func(s string) string { return s })
// filterItemsByStrings(wantedStrings, stringSlice2, func(s string) string { return s })
//
// It returns a list of strings (items whose stringFunc() exists in the list of wantedStrings).
func FilterItemsByStrings[T any](wantedStrings []string, possibleItems []T, stringFunc func(T) string) []string {
func filterItemsByStrings[T any](wantedStrings []string, possibleItems []T, stringFunc func(T) string) []string {
m := make(map[string]bool)
for _, item := range wantedStrings {
m[item] = true
Expand All @@ -67,14 +67,14 @@ func FilterItemsByStrings[T any](wantedStrings []string, possibleItems []T, stri
return res
}

// FilterOutItems is a generic function to return the subset of allItems which does not include the items specified in
// filterOutItems is a generic function to return the subset of allItems which does not include the items specified in
// unwantedItems. stringFunc is a function which maps the unwantedItem type T to a string value. For example, one can
// convert a struct of type *config.Workload to a string by passing
//
// func(w *config.Workload) string { return w.Name }
//
// as the stringFunc parameter.
func FilterOutItems[T any](allItems []string, unwantedItems []T, stringFunc func(T) string) []string {
func filterOutItems[T any](allItems []string, unwantedItems []T, stringFunc func(T) string) []string {
isUnwanted := make(map[string]bool)
for _, item := range unwantedItems {
isUnwanted[stringFunc(item)] = true
Expand Down Expand Up @@ -355,7 +355,7 @@ func (o *deployOpts) getDeploymentOrder() ([][]string, error) {
if err != nil {
return nil, err
}
workloadsToAppend := FilterOutItems(localWorkloads, specifiedWorkloadList, func(s string) string { return s })
workloadsToAppend := filterOutItems(localWorkloads, specifiedWorkloadList, func(s string) string { return s })
if len(workloadsToAppend) != 0 {
groupsMap[math.MaxInt] = append(groupsMap[math.MaxInt], workloadsToAppend...)
}
Expand All @@ -365,7 +365,7 @@ func (o *deployOpts) getDeploymentOrder() ([][]string, error) {
if err != nil {
return nil, err
}
workloadsToAppend := FilterOutItems(initializedWorkloads, specifiedWorkloadList, func(s string) string { return s })
workloadsToAppend := filterOutItems(initializedWorkloads, specifiedWorkloadList, func(s string) string { return s })
if len(workloadsToAppend) != 0 {
groupsMap[math.MaxInt] = append(groupsMap[math.MaxInt], workloadsToAppend...)
}
Expand Down Expand Up @@ -429,7 +429,7 @@ func (o *deployOpts) listInitializedLocalWorkloads() ([]string, error) {
return nil, err
}

o.initializedWsWorkloads = FilterItemsByStrings(localWorkloads, storeWls, func(workload *config.Workload) string { return workload.Name })
o.initializedWsWorkloads = filterItemsByStrings(localWorkloads, storeWls, func(workload *config.Workload) string { return workload.Name })
return o.initializedWsWorkloads, nil
}

Expand Down Expand Up @@ -742,18 +742,20 @@ func BuildDeployCmd() *cobra.Command {
Long: "Deploy one or more Copilot jobs or services.",
Example: `
Deploys a service named "frontend" to a "test" environment.
/code $ copilot deploy --name frontend --env test --deploy-env=false
/code $ copilot deploy --name frontend --env test
Deploys a job named "mailer" with additional resource tags to a "prod" environment.
/code $ copilot deploy -n mailer -e prod --resource-tags source/revision=bb133e7,deployment/initiator=manual --deploy-env=false
Initializes and deploys an environment named "test" in us-west-2 under the "default" profile with local manifest,
then deploys a service named "api"
/code $ copilot deploy --init-env --deploy-env --env test --name api --profile default --region us-west-2
Initializes and deploys a service named "backend" to a "prod" environment.
/code $ copilot deploy --init-wkld --deploy-env=false --env prod --name backend
/code $ copilot deploy --init-wkld --env prod --name backend
Deploys all local, initialized workloads in no particular order.
/code $ copilot deploy --all --env prod --name backend --init-wkld=false
/code $ copilot deploy --all --env prod --name backend
Deploys multiple workloads in a prescribed order (fe and worker, then be).
/code $ copilot deploy -n fe/1 -n be/2 -n worker/1`,
/code $ copilot deploy -n fe/1 -n be/2 -n worker/1
Initializes and deploys all local workloads after deploying environment changes.
/code $ copilot deploy --all --init-wkld --deploy-env -e prod`,

RunE: runCmdE(func(cmd *cobra.Command, args []string) error {
opts, err := newDeployOpts(vars)
Expand Down
18 changes: 9 additions & 9 deletions internal/pkg/term/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ func (s *LocalWorkloadSelector) getWorkloadSelectOptions(workloadType string) ([
return nil, fmt.Errorf("no %s found in workspace", pluralNounString)
}
// Get the list of un-initialized workloads that are present in the workspace and add them to options.
unInitializedLocalWorkloads := FilterOutItems(wsWlNames, initializedLocalWorkloads, func(a string) string { return a })
unInitializedLocalWorkloads := filterOutItems(wsWlNames, initializedLocalWorkloads, func(a string) string { return a })
for _, wl := range unInitializedLocalWorkloads {
options = append(options, prompt.Option{
Value: wl,
Expand Down Expand Up @@ -885,14 +885,14 @@ func (s *LocalWorkloadSelector) Workload(msg, help string) (wl string, err error
return selectedWlName, nil
}

// FilterOutItems is a generic function to return the subset of allItems which does not include the items specified in
// filterOutItems is a generic function to return the subset of allItems which does not include the items specified in
// unwantedItems. stringFunc is a function which maps the unwantedItem type T to a string value. For example, one can
// convert a struct of type *config.Workload to a string by passing
//
// func(w *config.Workload) string { return w.Name }
//
// as the stringFunc parameter.
func FilterOutItems[T any](allItems []string, unwantedItems []T, stringFunc func(T) string) []string {
func filterOutItems[T any](allItems []string, unwantedItems []T, stringFunc func(T) string) []string {
isUnwanted := make(map[string]bool)
for _, item := range unwantedItems {
isUnwanted[stringFunc(item)] = true
Expand Down Expand Up @@ -937,25 +937,25 @@ func (s *LocalEnvironmentSelector) LocalEnvironment(msg, help string) (string, e
}

func filterEnvsByName(envs []*config.Environment, wantedNames []string) []string {
return FilterItemsByStrings(wantedNames, envs, func(e *config.Environment) string { return e.Name })
return filterItemsByStrings(wantedNames, envs, func(e *config.Environment) string { return e.Name })
}

func filterWlsByName(wls []*config.Workload, wantedNames []string) []string {
return FilterItemsByStrings(wantedNames, wls, func(w *config.Workload) string { return w.Name })
return filterItemsByStrings(wantedNames, wls, func(w *config.Workload) string { return w.Name })
}

// FilterItemsByStrings is a generic function to return the subset of wantedStrings that exists in possibleItems.
// filterItemsByStrings is a generic function to return the subset of wantedStrings that exists in possibleItems.
// stringFunc is a method to convert the generic item type (T) to a string; for example, one can convert a struct of type
// *config.Workload to a string by passing
//
// func(w *config.Workload) string { return w.Name }.
//
// Likewise, FilterItemsByStrings can work on a list of strings by returning the unmodified item:
// Likewise, filterItemsByStrings can work on a list of strings by returning the unmodified item:
//
// FilterItemsByStrings(wantedStrings, stringSlice2, func(s string) string { return s })
// filterItemsByStrings(wantedStrings, stringSlice2, func(s string) string { return s })
//
// It returns a list of strings (items whose stringFunc() exists in the list of wantedStrings).
func FilterItemsByStrings[T any](wantedStrings []string, possibleItems []T, stringFunc func(T) string) []string {
func filterItemsByStrings[T any](wantedStrings []string, possibleItems []T, stringFunc func(T) string) []string {
m := make(map[string]bool)
for _, item := range wantedStrings {
m[item] = true
Expand Down

0 comments on commit eafbce3

Please sign in to comment.