Skip to content

Commit

Permalink
chore: flatten commands
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Dec 24, 2024
1 parent 8450ac0 commit b8d4f1c
Show file tree
Hide file tree
Showing 24 changed files with 203 additions and 215 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/node_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:
- name: Run Ubuntu commands
run: |
go build .
./algorun-tui node install
./algorun-tui install
systemctl status algorand.service
export TOKEN=$(cat /var/lib/algorand/algod.admin.token)
curl http://localhost:8080/v2/participation -H "X-Algo-API-Token: $TOKEN" | grep "null"
./algorun-tui node stop
./algorun-tui node upgrade
./algorun-tui node stop
./algorun-tui node uninstall
./algorun-tui stop
./algorun-tui upgrade
./algorun-tui stop
./algorun-tui uninstall
macos:
runs-on: macos-latest
Expand All @@ -45,12 +45,12 @@ jobs:
- name: Run MacOs commands
run: |
go build .
./algorun-tui node install
./algorun-tui install
sudo launchctl print system/com.algorand.algod
sleep 5
export TOKEN=$(cat ~/.algorand/algod.admin.token)
curl http://localhost:8080/v2/participation -H "X-Algo-API-Token: $TOKEN" | grep "null"
./algorun-tui node stop
./algorun-tui node upgrade
./algorun-tui node stop
./algorun-tui node uninstall
./algorun-tui stop
./algorun-tui upgrade
./algorun-tui stop
./algorun-tui uninstall
30 changes: 24 additions & 6 deletions cmd/node/bootstrap.go → cmd/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package node
package cmd

import (
"context"
"fmt"
"github.com/algorandfoundation/algorun-tui/api"
cmdutils "github.com/algorandfoundation/algorun-tui/cmd/utils"
"github.com/algorandfoundation/algorun-tui/cmd/utils/explanations"
"github.com/algorandfoundation/algorun-tui/internal/algod"
"github.com/algorandfoundation/algorun-tui/internal/algod/utils"
"github.com/algorandfoundation/algorun-tui/internal/system"
Expand All @@ -14,12 +15,29 @@ import (
"github.com/algorandfoundation/algorun-tui/ui/style"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
"time"
)

var in = `# Welcome!
var bootstrapCmdShort = "Initialize a fresh node. Alias for install, catchup, and start."

// cmdLong provides a detailed description of the Fast-Catchup feature, explaining its purpose and expected sync durations.
var bootstrapCmdLong = lipgloss.JoinVertical(
lipgloss.Left,
style.BANNER,
"",
style.Bold(bootstrapCmdShort),
"",
style.BoldUnderline("Overview:"),
"Get up and running with a fresh Algorand node.",
"Uses the local package manager to install Algorand, and then starts the node and preforms a Fast-Catchup.",
"",
style.Yellow.Render("Note: This command only supports the default data directory, /var/lib/algorand"),
)

var tutorial = `# Welcome!
This is the beginning of your adventure into running the an Algorand node!
Expand All @@ -30,15 +48,15 @@ Morbi mauris quam, ornare ac commodo et, posuere id sem. Nulla id condimentum ma
// bootstrapCmd defines the "debug" command used to display diagnostic information for developers, including debug data.
var bootstrapCmd = &cobra.Command{
Use: "bootstrap",
Short: "Initialize a fresh node. Alias for install, catchup, and start.",
Long: "Text",
Short: bootstrapCmdShort,
Long: bootstrapCmdLong,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
httpPkg := new(api.HttpPkg)

fmt.Print(style.Purple(style.BANNER))
out, err := glamour.Render(in, "dark")
out, err := glamour.Render(tutorial, "dark")
if err != nil {
return err
}
Expand All @@ -65,7 +83,7 @@ var bootstrapCmd = &cobra.Command{
return nil
}

log.Warn(style.Yellow.Render(SudoWarningMsg))
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))
if msg.Install && !algod.IsInstalled() {
err := algod.Install()
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions cmd/node/catchup/catchup.go → cmd/catchup/catchup.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package catchup

import (
"context"
"github.com/algorandfoundation/algorun-tui/api"
"github.com/algorandfoundation/algorun-tui/cmd/utils"
"github.com/algorandfoundation/algorun-tui/internal/algod"
"github.com/algorandfoundation/algorun-tui/ui/style"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var (
// dataDir path to the algorand data folder
dataDir string = ""

// defaultLag represents the default minimum catchup delay in milliseconds for the Fast Catchup process.
defaultLag int = 30_000

// force indicates whether to bypass certain checks or enforcement logic within a function or command execution flow.
force bool = false

Expand All @@ -33,6 +40,35 @@ var (
Use: "catchup",
Short: "Manage Fast-Catchup for your node",
Long: cmdLong,
Run: func(cmd *cobra.Command, args []string) {
// Create Clients
ctx := context.Background()
httpPkg := new(api.HttpPkg)
client, err := algod.GetClient(dataDir)
cobra.CheckErr(err)

// Fetch Status from Node
status, response, err := algod.NewStatus(ctx, client, httpPkg)
utils.WithInvalidResponsesExplanations(err, response, cmd.UsageString())
if status.State == algod.FastCatchupState {
log.Fatal(style.Red.Render("Node is currently catching up"))
}

// Get the Latest Catchpoint
catchpoint, _, err := algod.GetLatestCatchpoint(httpPkg, status.Network)
if err != nil {
log.Fatal(err)
}
log.Info(style.Green.Render("Latest Catchpoint: " + catchpoint))

// Submit the Catchpoint to the Algod Node, using the StartCatchupParams to skip
res, _, err := algod.StartCatchup(ctx, client, catchpoint, &api.StartCatchupParams{Min: &defaultLag})
if err != nil {
log.Fatal(err)
}

log.Info(style.Green.Render(res))
},
}, &dataDir)
)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/node/catchup/start.go → cmd/catchup/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var startCmd = utils.WithAlgodFlags(&cobra.Command{
utils.WithInvalidResponsesExplanations(err, response, cmd.UsageString())

if status.State == algod.FastCatchupState {
log.Fatal(style.Red.Render("Node is currently catching up. Use --abort to cancel."))
log.Fatal(style.Red.Render("Node is currently catching up."))
}

// Get the latest catchpoint
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions cmd/node/debug.go → cmd/debug.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package node
package cmd

import (
"encoding/json"
"fmt"
"github.com/algorandfoundation/algorun-tui/cmd/utils/explanations"
"github.com/algorandfoundation/algorun-tui/internal/algod"
"github.com/algorandfoundation/algorun-tui/internal/algod/utils"
"github.com/algorandfoundation/algorun-tui/internal/system"
Expand Down Expand Up @@ -47,7 +48,7 @@ var debugCmd = &cobra.Command{
log.Info("Collecting debug information...")

// Warn user for prompt
log.Warn(style.Yellow.Render(SudoWarningMsg))
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))

paths := utils.GetKnownDataPaths()
path, _ := exec.LookPath("algod")
Expand Down
9 changes: 7 additions & 2 deletions cmd/node/install.go → cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node
package cmd

import (
"github.com/algorandfoundation/algorun-tui/cmd/utils/explanations"
"github.com/algorandfoundation/algorun-tui/internal/algod"
"github.com/algorandfoundation/algorun-tui/ui/style"
"github.com/charmbracelet/log"
Expand All @@ -15,6 +16,10 @@ const InstallMsg = "Installing Algorand"
// InstallExistsMsg is a constant string used to indicate that the Algod is already installed on the system.
const InstallExistsMsg = "algod is already installed"

var installShort = "Install the algorand daemon"

var installLong = style.Purple(style.BANNER) + "\n" + style.LightBlue("Install the algorand daemon on your local machine")

// installCmd is a Cobra command that installs the Algorand daemon on the local machine, ensuring the service is operational.
var installCmd = &cobra.Command{
Use: "install",
Expand All @@ -27,7 +32,7 @@ var installCmd = &cobra.Command{
// TODO: get expected version
log.Info(style.Green.Render(InstallMsg))
// Warn user for prompt
log.Warn(style.Yellow.Render(SudoWarningMsg))
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))

// TODO: compare expected version to existing version
if algod.IsInstalled() && !force {
Expand Down
90 changes: 0 additions & 90 deletions cmd/node/node.go

This file was deleted.

68 changes: 0 additions & 68 deletions cmd/node/sync.go

This file was deleted.

Loading

0 comments on commit b8d4f1c

Please sign in to comment.