Skip to content

Commit

Permalink
Merge pull request #55 from ewilliams0305/override-flag
Browse files Browse the repository at this point in the history
Override flag
  • Loading branch information
ewilliams0305 committed Dec 30, 2023
2 parents 60641f7 + 31636a3 commit 290d776
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
],

},
{

"name": "Override Program Load",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./cmd/vcli/",
"console": "externalTerminal",
"args": [
"-h", "10.0.0.111",
"-t","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ijk0NDliMDM0LTcyNWEtNDM0Ny04YTMzLTc5Zjg2MDNlYjUyYiIsImx2IjoiRGVmYXVsdCBMZXZlbCIsInZlciI6IjEuMCIsImV4cGkiOiIwIn0.oMs434gmWR-x4sTGKonmndOA5F62FdzrwYZQYSGNd2A",
"-f", "C:\\Users\\ewilliams\\OneDrive - cenero.com\\Documents\\Projects\\WWF\\CEN22-9238\\Control Code\\9238_WWF_MPR_CP4N_v3.4.lpz",
"-n", "Wharton Template",
"-o"
],
},
{

"name": "Create And Run Room",
Expand Down
28 changes: 27 additions & 1 deletion pkg/tui/actions_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tui
import (
"fmt"
"os"
"strings"
"time"

"github.com/charmbracelet/bubbles/progress"
Expand Down Expand Up @@ -178,9 +179,34 @@ func actionsTickCmd() tea.Cmd {

func CreateProgramAction(options *vc.ProgramOptions) tea.Cmd {

if !OverrideFile {
return func() tea.Msg {
return CreateNewProgram(*options)
}
}

return func() tea.Msg {
return CreateNewProgram(*options)
programs, err := server.GetPrograms()
if err != nil {
return err
}

var prog *vc.ProgramEntry
for _, p := range programs {
if strings.HasSuffix(options.Name, p.FriendlyName) {
prog = &p
break
}
}
if prog == nil {
return nil
}

options.ProgramId = int(prog.ProgramID)
options.StartNow = true
return EditProgram(*options)
}

}

func CreateAndRunRoomAction(progOps *vc.ProgramOptions, roomOps *vc.RoomOptions) tea.Cmd {
Expand Down
20 changes: 13 additions & 7 deletions pkg/tui/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ var (
RoomID string
// Actions include GET PUT DEL and can be used with a combination of the Room ID and program file flags
Action string
// When the -o flag is provided the application will override the provided room.
OverrideFile bool
)

func InitFlags() {
const (
defaultHost = "127.0.0.1"
defaultToken = ""
hostFlagUsage = "The IP or hostname of the virtual control service"
tokenFlagUsage = "The API token generated from the VC4 webpage, this is required to control an external appliance"
progFlagUsage = "An optional flag to load a program file"
nameFagUsage = "An optional glag used to name the loaded program flag"
roomFlagUsage = "An optional room ID used to spin up a new room"
defaultHost = "127.0.0.1"
defaultToken = ""
hostFlagUsage = "The IP or hostname of the virtual control service"
tokenFlagUsage = "The API token generated from the VC4 webpage, this is required to control an external appliance"
progFlagUsage = "An optional flag to load a program file"
nameFagUsage = "An optional glag used to name the loaded program flag"
roomFlagUsage = "An optional room ID used to spin up a new room"
overrideFlagUsage = "An option flag to let the application know to override the provided program file"
)

flag.StringVar(&Hostname, "host", defaultHost, hostFlagUsage)
Expand All @@ -44,4 +47,7 @@ func InitFlags() {

flag.StringVar(&ProgramName, "name", "", nameFagUsage)
flag.StringVar(&ProgramName, "n", "", nameFagUsage+" (shorthand)")

flag.BoolVar(&OverrideFile, "override", false, overrideFlagUsage)
flag.BoolVar(&OverrideFile, "o", false, overrideFlagUsage+" (shorthand)")
}

0 comments on commit 290d776

Please sign in to comment.