Skip to content

Commit

Permalink
feat(check): New command to check Login Items are up-to-date (#50)
Browse files Browse the repository at this point in the history
<!-- markdownlint-disable MD041 -->

**Issue:** close #33

### Checklist

It returns an error if it's out-of-date.

- [x] This Pull Request introduces a new feature.
- [ ] This Pull Request fixes a bug.

### Description

<!--
A clear and concise description
  - Why did you make this change?
  - Please describe how this method is better than others.
-->

<br />

- [x] I agree to follow the [Code of
Conduct](https://github.com/5ouma/mli/blob/main/.github/CODE_OF_CONDUCT.md).
  • Loading branch information
5ouma authored Mar 9, 2024
1 parent ed06b4e commit b37ede3
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 3 deletions.
33 changes: 31 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Usage:
mli [command]
Available Commands:
check Check Login Items
help Help about any command
load Load Login Items
save Save Login Items
Expand Down Expand Up @@ -101,7 +102,7 @@ Use "mli [command] --help" for more information about a command.
media="(prefers-color-scheme: dark)"
/>
<!-- markdownlint-disable MD013 -->
<img alt="Load command GIF image generated VHS" src="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/light/load.gif" />
<img alt="Load command GIF image generated by VHS" src="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/light/load.gif" />
</picture>
</div>

Expand Down Expand Up @@ -132,7 +133,35 @@ Use "mli [command] --help" for more information about a command.
media="(prefers-color-scheme: dark)"
/>
<!-- markdownlint-disable MD013 -->
<img alt="Load command GIF image generated VHS" src="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/light/save.gif" />
<img alt="Load command GIF image generated by VHS" src="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/light/save.gif" />
</picture>
</div>

- ### πŸ” `Check`

```shell
πŸ” Check the Login Items are up-to-date
Usage:
mli check [flags]
Flags:
--file string Check Login Items from this JSON file (default "./login_items.json")
-h, --help help for check
```

<div align="center">
<picture>
<source
srcset="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/light/check.gif"
media="(prefers-color-scheme: light)"
/>
<source
srcset="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/dark/check.gif"
media="(prefers-color-scheme: dark)"
/>
<!-- markdownlint-disable MD013 -->
<img alt="Check command GIF image generated by VHS" src="https://raw.githubusercontent.com/5ouma/mli/HEAD/.github/assets/vhs/light/check.gif" />
</picture>
</div>

Expand Down
15 changes: 15 additions & 0 deletions .github/assets/vhs/dark/check.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Output .github/assets/vhs/dark/check.gif

Require mli

Set FontSize 40
Set Height 600
Set Width 1800
Set Theme { "background": "#161b22", "foreground": "#f4f4f4", "cursor": "#f4f4f4" }
Set Padding 30
Set TypingSpeed 100ms

Type "mli check --file='.github/assets/example/login_items.json'"
Sleep 1s
Enter
Sleep 5s
15 changes: 15 additions & 0 deletions .github/assets/vhs/light/check.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Output .github/assets/vhs/light/check.gif

Require mli

Set FontSize 40
Set Height 600
Set Width 1800
Set Theme { "background": "#f7f8fa", "foreground": "#242424", "cursor": "#242424" }
Set Padding 30
Set TypingSpeed 100ms

Type "mli check --file='.github/assets/example/login_items.json'"
Sleep 1s
Enter
Sleep 5s
2 changes: 1 addition & 1 deletion .github/assets/vhs/light/load.tape
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Set Height 600
Set Width 1800
Set Theme { "background": "#f7f8fa", "foreground": "#242424", "cursor": "#242424" }
Set Padding 30
Set TypingSpeed 80ms
Set TypingSpeed 100ms

Type "mli load --file='.github/assets/example/login_items.json'"
Sleep 1s
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/vhs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ jobs:
with:
path: ".github/assets/vhs/light/save.tape"

- name: β˜€οΈ Record Light Check Tape
uses: charmbracelet/vhs-action@v2
with:
path: ".github/assets/vhs/light/check.tape"

- name: πŸŒ• Record Dark Load Tape
uses: charmbracelet/vhs-action@v2
with:
Expand All @@ -51,6 +56,11 @@ jobs:
with:
path: ".github/assets/vhs/dark/save.tape"

- name: πŸŒ• Record Dark Check Tape
uses: charmbracelet/vhs-action@v2
with:
path: ".github/assets/vhs/dark/check.tape"

- name: 🎈 Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
Expand Down
47 changes: 47 additions & 0 deletions cmd/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"fmt"
"path/filepath"
"reflect"

"github.com/5ouma/mli/lib"
"github.com/spf13/cobra"
)

func (cmd *cmd) newCheckCmd() *cobra.Command {
checkCmd := &cobra.Command{
Use: "check",
Short: "Check Login Items",
Long: "πŸ” Check the Login Items are up-to-date",
Args: cobra.NoArgs,
RunE: cmd.execCheckCmd,
}
checkCmd.Flags().String("file", "./login_items.json", "Check Login Items from this JSON file")
return checkCmd
}

func (cmd *cmd) execCheckCmd(command *cobra.Command, args []string) error {
file, err := command.Flags().GetString("file")
if err != nil {
return err
}
path, err := filepath.Abs(file)
if err != nil {
return err
}

if err := cmd.loginItems.Load(path); err != nil {
return err
}
loginItems := new(lib.LoginItems)
if err := loginItems.Get(); err != nil {
return err
}
if !reflect.DeepEqual(cmd.loginItems, loginItems) {
return fmt.Errorf("login items are out-of-date")
}
fmt.Println("βœ… Login Items are up-to-date!")

return nil
}
1 change: 1 addition & 0 deletions cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func New() *cmd {
cmd.command.SetVersionTemplate("πŸ“‘ {{.Use}} {{.Version}}\n")
cmd.command.SetErrPrefix("🚨")
cmd.command.AddCommand(
cmd.newCheckCmd(),
cmd.newLoadCmd(),
cmd.newSaveCmd(),
)
Expand Down

0 comments on commit b37ede3

Please sign in to comment.