The goal of this PR is to normalize the cli packages in a way that 1/ showcases clear ownership of data, 2/ minimizes package bloat, and 3/ helps avoid circular import issues. To achieve this, two primary changes were made. First, the cli/options package was folded into cli/utils, so that all "shared functionality" is owned by a single package. Second, all flag values, globals, declarations, and mutator funcs (in the cli layer, logging package was not changed) were extracted from cli/utils and placed into cli/flags. This divides ownership between the declaration and population of the flags (cli/flags) from the utilization of values derived from flags in command processing (cli/utils). This PR contains zero logical changes. Only code movement and renaming. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #3664 #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/alcionai/corso/src/internal/common/dttm"
|
|
"github.com/alcionai/corso/src/pkg/path"
|
|
"github.com/alcionai/corso/src/pkg/selectors"
|
|
)
|
|
|
|
// IsValidTimeFormat returns true if the input is recognized as a
|
|
// supported format by the common time parser.
|
|
func IsValidTimeFormat(in string) bool {
|
|
_, err := dttm.ParseTime(in)
|
|
return err == nil
|
|
}
|
|
|
|
// IsValidTimeFormat returns true if the input is recognized as a
|
|
// boolean.
|
|
func IsValidBool(in string) bool {
|
|
_, err := strconv.ParseBool(in)
|
|
return err == nil
|
|
}
|
|
|
|
// trimFolderSlash takes a set of folder paths and returns a set of folder paths
|
|
// with any unescaped trailing `/` characters removed.
|
|
func trimFolderSlash(folders []string) []string {
|
|
res := make([]string, 0, len(folders))
|
|
|
|
for _, p := range folders {
|
|
if p == string(path.PathSeparator) {
|
|
res = selectors.Any()
|
|
break
|
|
}
|
|
|
|
// Use path package because it has logic to handle escaping already.
|
|
res = append(res, path.TrimTrailingSlash(p))
|
|
}
|
|
|
|
return res
|
|
}
|