diff --git a/backend/app/cmd/backup.go b/backend/app/cmd/backup.go index 96c22387..4f92ad42 100644 --- a/backend/app/cmd/backup.go +++ b/backend/app/cmd/backup.go @@ -22,11 +22,6 @@ type BackupCommand struct { CommonOpts } -// SetCommon satisfies main.CommonOptionsCommander interface and sets common options -func (ec *BackupCommand) SetCommon(commonOpts CommonOpts) { - ec.CommonOpts = commonOpts -} - // Execute runs export with ExportCommand parameters, entry point for "export" command func (ec *BackupCommand) Execute(args []string) error { log.Printf("[INFO] export to %s, site %s", ec.ExportPath, ec.Site) diff --git a/backend/app/cmd/cmd.go b/backend/app/cmd/cmd.go index 42b6e2bd..6997e175 100644 --- a/backend/app/cmd/cmd.go +++ b/backend/app/cmd/cmd.go @@ -19,12 +19,25 @@ import ( // Revision sets from main var Revision = "unknown" +// CommonOptionsCommander extends flags.Commander with SetCommon +// All commands should implement this interfaces +type CommonOptionsCommander interface { + SetCommon(commonOpts CommonOpts) + Execute(args []string) error +} + // CommonOpts sets externally from main, shared across all commands type CommonOpts struct { RemarkURL string SharedSecret string } +// SetCommon satisfies CommonOptionsCommander interface and sets common option fields +func (c *CommonOpts) SetCommon(commonOpts CommonOpts) { + c.RemarkURL = commonOpts.RemarkURL + c.SharedSecret = commonOpts.SharedSecret +} + // fileParser used to convert template strings like blah-{{.SITE}}-{{.YYYYMMDD}} the final format type fileParser struct { site string diff --git a/backend/app/cmd/import.go b/backend/app/cmd/import.go index cbb56180..d81d4b7c 100644 --- a/backend/app/cmd/import.go +++ b/backend/app/cmd/import.go @@ -24,11 +24,6 @@ type ImportCommand struct { CommonOpts } -// SetCommon satisfies main.CommonOptionsCommander interface and sets common options -func (ic *ImportCommand) SetCommon(commonOpts CommonOpts) { - ic.CommonOpts = commonOpts -} - // Execute runs import with ImportCommand parameters, entry point for "import" command func (ic *ImportCommand) Execute(args []string) error { log.Printf("[INFO] import %s (%s), site %s", ic.InputFile, ic.Provider, ic.Site) diff --git a/backend/app/cmd/restore.go b/backend/app/cmd/restore.go index ce9013c5..fe4589c8 100644 --- a/backend/app/cmd/restore.go +++ b/backend/app/cmd/restore.go @@ -15,11 +15,6 @@ type RestoreCommand struct { CommonOpts } -// SetCommon satisfies main.CommonOptionsCommander interface and sets common options -func (rc *RestoreCommand) SetCommon(commonOpts CommonOpts) { - rc.CommonOpts = commonOpts -} - // Execute runs import with RestoreCommand parameters, entry point for "restore" command // uses ImportCommand with constructed full file name func (rc *RestoreCommand) Execute(args []string) error { diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index 40f7b6d9..ebb7167b 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -130,11 +130,6 @@ type serverApp struct { terminated chan struct{} } -// SetCommon satisfies CommonOptionsCommander interface and sets common options -func (s *ServerCommand) SetCommon(commonOpts CommonOpts) { - s.CommonOpts = commonOpts -} - // Execute is the entry point for "server" command, called by flag parser func (s *ServerCommand) Execute(args []string) error { log.Printf("[INFO] start server on port %d", s.Port) diff --git a/backend/app/main.go b/backend/app/main.go index b0ee2da5..00eed26f 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -26,13 +26,6 @@ type Opts struct { var revision = "unknown" -// CommonOptionsCommander extends flags.Commander with SetCommon -// All commands should implement this interfaces -type CommonOptionsCommander interface { - SetCommon(commonOpts cmd.CommonOpts) - Execute(args []string) error -} - func main() { fmt.Printf("remark42 %s\n", revision) cmd.Revision = revision @@ -42,7 +35,7 @@ func main() { p.CommandHandler = func(command flags.Commander, args []string) error { setupLog(opts.Dbg) commonOpts := cmd.CommonOpts{RemarkURL: opts.RemarkURL, SharedSecret: opts.SharedSecret} - c := command.(CommonOptionsCommander) + c := command.(cmd.CommonOptionsCommander) c.SetCommon(commonOpts) err := c.Execute(args) if err != nil {