Skip to content

Commit

Permalink
stage any local file (#18)
Browse files Browse the repository at this point in the history
* stage any local file

* version bump, removed useless stuff

* upgrade dependencies
  • Loading branch information
pygrum authored Dec 25, 2023
1 parent d072cb2 commit 1ec1da0
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 148 deletions.
18 changes: 18 additions & 0 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ func ConsoleCommands() []*grumble.Command {
},
}

cmdStage.AddCommand(&grumble.Command{
Name: "local",
Help: "stage a file on disk on an endpoint",
Args: func(a *grumble.Args) {
a.String("file", "name of file to stage")
},
Flags: func(f *grumble.Flags) {
f.StringL("as", "", "the alias used to stage your file")
},
Run: func(c *grumble.Context) error {
stageLocalCmd(c.Args.String("file"), c.Flags.String("as"))
return nil
},
Completer: func(prefix string, args []string) []string {
return completion.LocalPathCompleter(prefix)
},
})

cmdUnstage := &grumble.Command{
Name: "unstage",
Help: "unstage a staged agent, by specifying its stage alias (e.g. index.php)",
Expand Down
23 changes: 23 additions & 0 deletions pkg/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,26 @@ func installCmd(repoUrl, branch string, useCreds bool) {
log.NumericalLevel(cLogger, uint16(notif.LogLevel), notif.Msg)
}
}

// installs local repositories / folders
func localCmd(path string) {
stream, err := console.Rpc.Install(ctx, &clientpb.InstallRequest{
Path: path,
Source: clientpb.InstallRequest_Local,
})
if err != nil {
cLogger.Error("%v", err)
return
}
for {
notif, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
cLogger.Error("install failed: %v", err)
return
}
log.NumericalLevel(cLogger, uint16(notif.LogLevel), notif.Msg)
}
}
31 changes: 0 additions & 31 deletions pkg/commands/install_local.go

This file was deleted.

29 changes: 25 additions & 4 deletions pkg/commands/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"github.com/pygrum/monarch/pkg/console"
"github.com/pygrum/monarch/pkg/log"
"github.com/pygrum/monarch/pkg/protobuf/clientpb"
"os"
"path/filepath"
"strings"
)

func stageCmd(arg string, as string) {
if len(arg) == 0 {
func stageCmd(agent string, as string) {
if len(agent) == 0 {
s, err := console.Rpc.StageView(ctx, &clientpb.Empty{})
if err != nil {
cLogger.Error("%v", err)
Expand All @@ -27,7 +29,26 @@ func stageCmd(arg string, as string) {
w.Flush()
return
}
notif, err := console.Rpc.StageAdd(ctx, &clientpb.StageAddRequest{Agent: arg, Alias: as})
notif, err := console.Rpc.StageAdd(ctx, &clientpb.StageAddRequest{Agent: agent, Alias: as})
if err != nil {
cLogger.Error("%v", err)
return
}
log.NumericalLevel(cLogger, uint16(notif.LogLevel), notif.Msg)
}

func stageLocalCmd(file string, as string) {
data, err := os.ReadFile(file)
if err != nil {
cLogger.Error("%v", err)
return
}
req := &clientpb.StageLocalRequest{
Filename: filepath.Base(file),
Data: data,
Alias: as,
}
notif, err := console.Rpc.StageLocal(ctx, req)
if err != nil {
cLogger.Error("%v", err)
return
Expand All @@ -37,7 +58,7 @@ func stageCmd(arg string, as string) {

func unstageCmd(name string) {
if _, err := console.Rpc.Unstage(ctx, &clientpb.UnstageRequest{Alias: name}); err != nil {
cLogger.Error("%v", err)
cLogger.Info("nothing is staged on %s", name)
return
}
cLogger.Info("unstaged %s", name)
Expand Down
6 changes: 1 addition & 5 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package consts

import "github.com/fatih/color"

const (
DockerfilesPath = "docker"
BuilderDockerfile = "builder/Dockerfile"

MonarchNet = "monarch-net"
Version = "0.0.2" // track with container
Version = "0.0.3" // track with container
ServerUser = "server"

CoopHelpGroup = "Co-op / Multiplayer"
GeneralHelpGroup = "General"
AdminHelpGroup = "Admin"
ServerHelpGroup = "Server"
BuildHelpGroup = "Build"

DefaultPrompt = "monarch > "
MainColor = color.FgMagenta
)
6 changes: 5 additions & 1 deletion pkg/handler/http/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ func (s *stage) Add(name, agent, path, stagedBy string) error {
return nil
}

func (s *stage) Rm(name string) {
func (s *stage) Rm(name string) bool {
if _, ok := s.fileNameMappings[name]; !ok {
return ok
}
delete(s.fileNameMappings, name)
return true
}

func (s *stage) get(name string) ([]byte, error) {
Expand Down
Loading

0 comments on commit 1ec1da0

Please sign in to comment.