Add -addr flag to replicate command

This commit is contained in:
Ben Johnson
2022-03-05 09:46:23 -07:00
parent 14026421b2
commit 7fe79d3883

View File

@@ -51,6 +51,7 @@ func NewReplicateCommand(stdin io.Reader, stdout, stderr io.Writer) *ReplicateCo
func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err error) { func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err error) {
fs := flag.NewFlagSet("litestream-replicate", flag.ContinueOnError) fs := flag.NewFlagSet("litestream-replicate", flag.ContinueOnError)
execFlag := fs.String("exec", "", "execute subcommand") execFlag := fs.String("exec", "", "execute subcommand")
addr := fs.String("addr", "", "HTTP bind address (host:port)")
registerConfigFlag(fs, &c.configPath, &c.noExpandEnv) registerConfigFlag(fs, &c.configPath, &c.noExpandEnv)
fs.Usage = c.Usage fs.Usage = c.Usage
if err := fs.Parse(args); err != nil { if err := fs.Parse(args); err != nil {
@@ -83,7 +84,10 @@ func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err e
} }
} }
// Override config exec command, if specified. // Override config with flags, if specified.
if *addr != "" {
c.Config.Addr = *addr
}
if *execFlag != "" { if *execFlag != "" {
c.Config.Exec = *execFlag c.Config.Exec = *execFlag
} }
@@ -147,6 +151,7 @@ func (c *ReplicateCommand) Run(ctx context.Context) (err error) {
if err := c.httpServer.Open(); err != nil { if err := c.httpServer.Open(); err != nil {
return fmt.Errorf("cannot start http server: %w", err) return fmt.Errorf("cannot start http server: %w", err)
} }
log.Printf("http server running at %s", c.httpServer.URL())
} }
// Parse exec commands args & start subprocess. // Parse exec commands args & start subprocess.