-
Notifications
You must be signed in to change notification settings - Fork 1
Add --listen-addr flag to anytype serve and anytype service install #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b070921
Add --listen-addr flag to anytype serve and anytype service install
jmetrikat f8ef426
Refactor service subcommands
jmetrikat 181773e
Fix effective api addr
jmetrikat fb2dbb7
Add serve and service tests
jmetrikat c0422e8
Update the test target to include download-tantivy as a dependency
jmetrikat 2d38a32
Update CI to make tests
jmetrikat 661e7ae
Bump golanci lint version
jmetrikat bdb0f1c
Fix lint
jmetrikat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,4 +44,4 @@ jobs: | |
| run: go mod download | ||
|
|
||
| - name: Run tests | ||
| run: go test -v ./... | ||
| run: make test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package serve | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/anyproto/anytype-cli/core/config" | ||
| ) | ||
|
|
||
| func TestNewServeCmd(t *testing.T) { | ||
| cmd := NewServeCmd() | ||
|
|
||
| if cmd.Use != "serve" { | ||
| t.Errorf("cmd.Use = %v, want serve", cmd.Use) | ||
| } | ||
|
|
||
| if len(cmd.Aliases) != 1 || cmd.Aliases[0] != "start" { | ||
| t.Errorf("cmd.Aliases = %v, want [start]", cmd.Aliases) | ||
| } | ||
| } | ||
|
|
||
| func TestServeCmd_ListenAddressFlag(t *testing.T) { | ||
| cmd := NewServeCmd() | ||
|
|
||
| flag := cmd.Flag("listen-address") | ||
| if flag == nil { | ||
| t.Fatal("listen-address flag not found") | ||
| return | ||
| } | ||
|
|
||
| if flag.DefValue != config.DefaultAPIAddress { | ||
| t.Errorf("listen-address default = %v, want %v", flag.DefValue, config.DefaultAPIAddress) | ||
| } | ||
|
|
||
| if flag.Usage != "API listen address in `host:port` format" { | ||
| t.Errorf("listen-address usage = %v, want 'API listen address in `host:port` format'", flag.Usage) | ||
| } | ||
| } | ||
|
|
||
| func TestServeCmd_ListenAddressFlagCustomValue(t *testing.T) { | ||
| cmd := NewServeCmd() | ||
|
|
||
| customAddr := "0.0.0.0:8080" | ||
| cmd.SetArgs([]string{"--listen-address", customAddr}) | ||
|
|
||
| if err := cmd.ParseFlags([]string{"--listen-address", customAddr}); err != nil { | ||
| t.Fatalf("Failed to parse flags: %v", err) | ||
| } | ||
|
|
||
| flag := cmd.Flag("listen-address") | ||
| if flag.Value.String() != customAddr { | ||
| t.Errorf("listen-address value = %v, want %v", flag.Value.String(), customAddr) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package install | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/anyproto/anytype-cli/core/config" | ||
| "github.com/anyproto/anytype-cli/core/output" | ||
| "github.com/anyproto/anytype-cli/core/serviceprogram" | ||
| ) | ||
|
|
||
| func NewInstallCmd() *cobra.Command { | ||
| var listenAddress string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "install", | ||
| Short: "Install as a user service", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| s, err := serviceprogram.GetServiceWithAddress(listenAddress) | ||
| if err != nil { | ||
| return output.Error("Failed to create service: %w", err) | ||
| } | ||
|
|
||
| err = s.Install() | ||
| if err != nil { | ||
| return output.Error("Failed to install service: %w", err) | ||
| } | ||
|
|
||
| output.Success("anytype service installed successfully") | ||
| if listenAddress != config.DefaultAPIAddress { | ||
| output.Info("API will listen on %s", listenAddress) | ||
| } | ||
| output.Print("\nTo manage the service:") | ||
| output.Print(" Start: anytype service start") | ||
| output.Print(" Stop: anytype service stop") | ||
| output.Print(" Restart: anytype service restart") | ||
| output.Print(" Status: anytype service status") | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&listenAddress, "listen-address", config.DefaultAPIAddress, "API listen address in `host:port` format") | ||
jmetrikat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return cmd | ||
| } | ||
jmetrikat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package install | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/anyproto/anytype-cli/core/config" | ||
| ) | ||
|
|
||
| func TestNewInstallCmd(t *testing.T) { | ||
| cmd := NewInstallCmd() | ||
|
|
||
| if cmd.Use != "install" { | ||
| t.Errorf("cmd.Use = %v, want install", cmd.Use) | ||
| } | ||
|
|
||
| if cmd.Short != "Install as a user service" { | ||
| t.Errorf("cmd.Short = %v, want 'Install as a user service'", cmd.Short) | ||
| } | ||
| } | ||
|
|
||
| func TestInstallCmd_ListenAddressFlag(t *testing.T) { | ||
| cmd := NewInstallCmd() | ||
|
|
||
| flag := cmd.Flag("listen-address") | ||
| if flag == nil { | ||
| t.Fatal("listen-address flag not found") | ||
| return | ||
| } | ||
|
|
||
| if flag.DefValue != config.DefaultAPIAddress { | ||
| t.Errorf("listen-address default = %v, want %v", flag.DefValue, config.DefaultAPIAddress) | ||
| } | ||
|
|
||
| if flag.Usage != "API listen address in `host:port` format" { | ||
| t.Errorf("listen-address usage = %v, want 'API listen address in `host:port` format'", flag.Usage) | ||
| } | ||
| } | ||
|
|
||
| func TestInstallCmd_ListenAddressFlagCustomValue(t *testing.T) { | ||
| cmd := NewInstallCmd() | ||
|
|
||
| customAddr := "0.0.0.0:9000" | ||
|
|
||
| if err := cmd.ParseFlags([]string{"--listen-address", customAddr}); err != nil { | ||
| t.Fatalf("Failed to parse flags: %v", err) | ||
| } | ||
|
|
||
| flag := cmd.Flag("listen-address") | ||
| if flag.Value.String() != customAddr { | ||
| t.Errorf("listen-address value = %v, want %v", flag.Value.String(), customAddr) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package restart | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/kardianos/service" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/anyproto/anytype-cli/core/output" | ||
| "github.com/anyproto/anytype-cli/core/serviceprogram" | ||
| ) | ||
|
|
||
| func NewRestartCmd() *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "restart", | ||
| Short: "Restart the service", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| s, err := serviceprogram.GetService() | ||
| if err != nil { | ||
| return output.Error("Failed to create service: %w", err) | ||
| } | ||
|
|
||
| _, err = s.Status() | ||
| if err != nil && errors.Is(err, service.ErrNotInstalled) { | ||
| output.Warning("anytype service is not installed") | ||
| output.Info("Run 'anytype service install' to install it first") | ||
| return nil | ||
| } | ||
|
|
||
| err = s.Restart() | ||
| if err != nil { | ||
| return output.Error("Failed to restart service: %w", err) | ||
| } | ||
|
|
||
| output.Success("anytype service restarted") | ||
| return nil | ||
| }, | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.