Skip to content

Commit

Permalink
make GetFlagString() process the default string
Browse files Browse the repository at this point in the history
since the dateFormat / --date has a default set to dd-mm-yyy, the
GetFlagString() function does not ever attempt reading the value from
the config file.

Now every GetFlagString() invocation explicitly lists the default
values, like GetFlagInt() does, hence one can override the date format
in the config file.
  • Loading branch information
klaernie authored and KonradIT committed Sep 4, 2024
1 parent 3ae07d9 commit 40c4245
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmd/apply_lut.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ var applyLutCmd = &cobra.Command{
Use: "apply-lut",
Short: "Apply LUT to one or more images",
Run: func(cmd *cobra.Command, _ []string) {
input := getFlagString(cmd, "input")
lutFile := getFlagString(cmd, "lut")
input := getFlagString(cmd, "input", "")
lutFile := getFlagString(cmd, "lut", "")

intensity := getFlagInt(cmd, "intensity", "100")
intensityParsed := float64(intensity) / 100

quality := getFlagInt(cmd, "quality", "100")
resizeTo := getFlagString(cmd, "resize")
resizeTo := getFlagString(cmd, "resize", "")

stat, err := os.Stat(input)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/export_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ var exportTags = &cobra.Command{
Use: "export-tags",
Short: "Export HiLight/other tags in video",
Run: func(cmd *cobra.Command, _ []string) {
input := getFlagString(cmd, "input")
format := getFlagString(cmd, "format")
output := getFlagString(cmd, "output")
input := getFlagString(cmd, "input", "")
format := getFlagString(cmd, "format", "")
output := getFlagString(cmd, "output", "")

stat, err := os.Stat(input)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import (
"github.com/spf13/viper"
)

func getFlagString(cmd *cobra.Command, name string) string {
func getFlagString(cmd *cobra.Command, name string, defaultString string) string {
value, err := cmd.Flags().GetString(name)
if err != nil {
cui.Error("Problem parsing "+name, err)
}
if value == "" {
value = viper.GetString(name)
}
if value == "" {
value = defaultString
}
return value
}

Expand Down
18 changes: 9 additions & 9 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var importCmd = &cobra.Command{
Use: "import",
Short: "Import media",
Run: func(cmd *cobra.Command, _ []string) {
input := getFlagString(cmd, "input")
output := getFlagString(cmd, "output")
camera := getFlagString(cmd, "camera")
projectName := getFlagString(cmd, "name")
input := getFlagString(cmd, "input", "")
output := getFlagString(cmd, "output", "")
camera := getFlagString(cmd, "camera", "")
projectName := getFlagString(cmd, "name", "")

if projectName != "" {
_, err := os.Stat(filepath.Join(output, projectName))
Expand All @@ -40,12 +40,12 @@ var importCmd = &cobra.Command{
}
}

dateFormat := getFlagString(cmd, "date")
dateFormat := getFlagString(cmd, "date", "dd-mm-yyyy")
bufferSize := getFlagInt(cmd, "buffer", "1000")
prefix := getFlagString(cmd, "prefix")
prefix := getFlagString(cmd, "prefix", "")
dateRange := getFlagSlice(cmd, "range")
cameraName := getFlagString(cmd, "camera-name")
connection := utils.ConnectionType(getFlagString(cmd, "connection"))
cameraName := getFlagString(cmd, "camera-name", "")
connection := utils.ConnectionType(getFlagString(cmd, "connection", ""))
skipAuxFiles := getFlagBool(cmd, "skip-aux", "true")
sortBy := getFlagSlice(cmd, "sort-by")
if len(sortBy) == 0 {
Expand Down Expand Up @@ -137,7 +137,7 @@ func init() {
importCmd.Flags().StringP("output", "o", "", "Output directory for sorted media")
importCmd.Flags().StringP("name", "n", "", "Project name")
importCmd.Flags().StringP("camera", "c", "", "Camera type")
importCmd.Flags().StringP("date", "d", "dd-mm-yyyy", "Date format, dd-mm-yyyy by default")
importCmd.Flags().StringP("date", "d", "", "Date format, dd-mm-yyyy by default")
importCmd.Flags().StringP("buffer", "b", "", "Buffer size for copying, default is 1000 bytes")
importCmd.Flags().StringP("prefix", "p", "", "Prefix for each file, pass `cameraname` to prepend the camera name (eg: Hero9 Black)")
importCmd.Flags().StringSlice("range", []string{}, "A date range, eg: 01-05-2020,05-05-2020 -- also accepted: `today`, `yesterday`, `week`")
Expand Down
6 changes: 3 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var updateCmd = &cobra.Command{
Use: "update",
Short: "Update camera firmware",
Run: func(cmd *cobra.Command, _ []string) {
input := getFlagString(cmd, "input")
camera := getFlagString(cmd, "camera")
input := getFlagString(cmd, "input", "")
camera := getFlagString(cmd, "camera", "")
c, err := utils.CameraGet(camera)
if err != nil {
cui.Error("Something went wrong", err)
Expand All @@ -25,7 +25,7 @@ var updateCmd = &cobra.Command{
cui.Error("Something went wrong", err)
}
case utils.Insta360:
model := getFlagString(cmd, "model")
model := getFlagString(cmd, "model", "")
err = insta360.UpdateCamera(input, model)
if err != nil {
cui.Error("Something went wrong", err)
Expand Down

0 comments on commit 40c4245

Please sign in to comment.