mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
move console commands to separate package
This commit is contained in:
parent
b2ad618781
commit
3af880042d
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"github.com/lus/pasty/internal/cleanup"
|
||||
"github.com/lus/pasty/internal/config"
|
||||
"github.com/lus/pasty/internal/consolecommands"
|
||||
"github.com/lus/pasty/internal/meta"
|
||||
"github.com/lus/pasty/internal/reports"
|
||||
"github.com/lus/pasty/internal/storage"
|
||||
@ -132,16 +133,18 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
// Listen to console commands if enabled
|
||||
if !cfg.ConsoleCommandsEnabled {
|
||||
log.Info().Msg("The application has been started. Use Ctrl+C to shut it down.")
|
||||
} else {
|
||||
log.Info().Msg("The application has been started and listens to console commands. Use Ctrl+C or 'stop' to shut it down.")
|
||||
go (&consoleCommandRouter{
|
||||
go (&consolecommands.Router{
|
||||
Config: cfg,
|
||||
Storage: driver,
|
||||
}).Listen()
|
||||
}
|
||||
|
||||
// Wait for an interrupt signal
|
||||
shutdownChan := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdownChan, os.Interrupt)
|
||||
<-shutdownChan
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package consolecommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (router *consoleCommandRouter) Cleanup(args []string) {
|
||||
func (router *Router) Cleanup(args []string) {
|
||||
if len(args) == 0 {
|
||||
fmt.Println("Expected 1 argument.")
|
||||
return
|
@ -1,11 +1,11 @@
|
||||
package main
|
||||
package consolecommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (router *consoleCommandRouter) Delete(args []string) {
|
||||
func (router *Router) Delete(args []string) {
|
||||
if len(args) == 0 {
|
||||
fmt.Println("Expected 1 argument.")
|
||||
return
|
@ -1,11 +1,11 @@
|
||||
package main
|
||||
package consolecommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (router *consoleCommandRouter) SetModificationToken(args []string) {
|
||||
func (router *Router) SetModificationToken(args []string) {
|
||||
if len(args) < 2 {
|
||||
fmt.Println("Expected 2 arguments.")
|
||||
return
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package consolecommands
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -14,12 +14,12 @@ import (
|
||||
|
||||
var whitespaceRegex = regexp.MustCompile("\\s+")
|
||||
|
||||
type consoleCommandRouter struct {
|
||||
type Router struct {
|
||||
Config *config.Config
|
||||
Storage storage.Driver
|
||||
}
|
||||
|
||||
func (router *consoleCommandRouter) Listen() {
|
||||
func (router *Router) Listen() {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
fmt.Print("> ")
|
Loading…
Reference in New Issue
Block a user