Skip to content

Commit

Permalink
Merge pull request #167 from kachick/default-prefix
Browse files Browse the repository at this point in the history
Provide default prefix
  • Loading branch information
kachick committed Apr 24, 2024
2 parents befd387 + c10ae3e commit 9925d7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 6 additions & 5 deletions cmd/selfup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`

Expand Down
3 changes: 2 additions & 1 deletion internal/selfup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9925d7a

Please sign in to comment.