diff --git a/README.md b/README.md index 8282138..4ea45c0 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Assume some GitHub actions workflow have lines like follows Then you can call selfup as this ```bash -selfup run --prefix='# selfup ' .github/workflows/*.yml +selfup run .github/workflows/*.yml ``` You can check the running plans with `list` subcommand ```console -> selfup list --prefix='# selfup ' .github/workflows/*.yml +> selfup list .github/workflows/*.yml .github/workflows/lint.yml:17: 0.40.2 ✓ .github/workflows/release.yml:37: 1.20.0 => 1.42.9 .github/workflows/lint.yml:24: 1.16.12 @@ -63,8 +63,10 @@ Changed from v0.0.3 ### Options -- `--skip-by`: skips to parse JSON and runs if the line includes this string -- `--no-color`: avoid to wrap colors even if executed in terminal +- `--prefix`: Set customized prefix to begin the JSON +- `--skip-by`: Skips to parse JSON and runs if the line includes this string +- `--no-color`: Avoid to wrap colors even if executed in terminal +- `--version`: Print the version ## Motivation diff --git a/cmd/selfup/main.go b/cmd/selfup/main.go index fbb5613..ece62a5 100644 --- a/cmd/selfup/main.go +++ b/cmd/selfup/main.go @@ -22,17 +22,18 @@ var ( ) func main() { + versionFlag := flag.Bool("version", false, "print the version of this program") + sharedFlags := flag.NewFlagSet("run|list", flag.ExitOnError) - prefixFlag := sharedFlags.String("prefix", "", "prefix to write json") + prefixFlag := sharedFlags.String("prefix", " selfup ", "prefix to begin json") skipByFlag := sharedFlags.String("skip-by", "", "skip to run if the line contains this string") noColorFlag := sharedFlags.Bool("no-color", false, "disable color output") - versionFlag := flag.Bool("version", false, "print the version of this program") const usage = `Usage: selfup [SUB] [OPTIONS] [PATH]... -$ selfup run --prefix='# selfup ' .github/workflows/*.yml -$ selfup run --prefix='# selfup ' --skip-by='nix run' .github/workflows/*.yml -$ selfup list --prefix='# selfup ' .github/workflows/*.yml +$ selfup run .github/workflows/*.yml +$ selfup run --prefix='# Update with this json: ' --skip-by='nix run' .github/workflows/*.yml +$ selfup list .github/workflows/*.yml $ selfup --version ` diff --git a/internal/selfup.go b/internal/selfup.go index 496be2b..ea4acdc 100644 --- a/internal/selfup.go +++ b/internal/selfup.go @@ -50,11 +50,12 @@ func Update(path string, prefix string, skipBy string, isColor bool) (Result, er newLines = append(newLines, line) continue } - head, tail, found := strings.Cut(line, prefix) + head, tail, found := strings.Cut(line, prefix+"{") if !found { newLines = append(newLines, line) continue } + tail = "{" + tail def := &Definition{} totalCount += 1