-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,280 additions
and
1,241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package configure | ||
|
||
import ( | ||
"errors" | ||
"github.com/algorandfoundation/algorun-tui/internal/algod" | ||
"github.com/algorandfoundation/algorun-tui/internal/system" | ||
"github.com/algorandfoundation/algorun-tui/ui/style" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var serviceCmd = &cobra.Command{ | ||
Use: "service", | ||
Short: "Configure the node service", | ||
Long: style.Purple(style.BANNER) + "\n" + style.LightBlue("Configure the service that runs the node."), | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
if !system.IsSudo() { | ||
return errors.New( | ||
"you need to be root to run this command. Please run this command with sudo") | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// TODO: Combine this with algod.UpdateService and algod.SetNetwork | ||
return algod.EnsureService() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package configure | ||
|
||
import ( | ||
"fmt" | ||
"github.com/algorandfoundation/algorun-tui/internal/system" | ||
"github.com/manifoldco/promptui" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
type Release struct { | ||
Name string `json:"name"` | ||
ZipballURL string `json:"zipball_url"` | ||
TarballURL string `json:"tarball_url"` | ||
Commit struct { | ||
Sha string `json:"sha"` | ||
URL string `json:"url"` | ||
} `json:"commit"` | ||
NodeID string `json:"node_id"` | ||
} | ||
|
||
// Queries user on the provided prompt and returns the user input | ||
func promptWrapperInput(promptLabel string) string { | ||
prompt := promptui.Prompt{ | ||
Label: promptLabel, | ||
} | ||
|
||
result, err := prompt.Run() | ||
cobra.CheckErr(err) | ||
|
||
return result | ||
} | ||
|
||
// Queries user on the provided prompt and returns true if user inputs "y" | ||
func promptWrapperYes(promptLabel string) bool { | ||
return promptWrapperInput(promptLabel) == "y" | ||
} | ||
|
||
// Queries user on the provided prompt and returns true if user does not input "y" | ||
// Included for improved readability of decision tree, despite being redundant. | ||
func promptWrapperNo(promptLabel string) bool { | ||
return promptWrapperInput(promptLabel) != "y" | ||
} | ||
|
||
// Queries user on the provided prompt and returns the selected item | ||
func promptWrapperSelection(promptLabel string, items []string) string { | ||
prompt := promptui.Select{ | ||
Label: promptLabel, | ||
Items: items, | ||
} | ||
|
||
_, result, err := prompt.Run() | ||
cobra.CheckErr(err) | ||
|
||
fmt.Printf("You selected: %s\n", result) | ||
|
||
return result | ||
} | ||
|
||
// TODO: consider replacing with a method that does more for the user | ||
func affectALGORAND_DATA(path string) { | ||
fmt.Println("Please execute the following in your terminal to set the environment variable:") | ||
fmt.Println("") | ||
fmt.Println("export ALGORAND_DATA=" + path) | ||
fmt.Println("") | ||
} | ||
|
||
func validateAlgorandDataDir(path string) bool { | ||
info, err := os.Stat(path) | ||
|
||
// Check if the path exists | ||
if os.IsNotExist(err) { | ||
return false | ||
} | ||
|
||
// Check if the path is a directory | ||
if !info.IsDir() { | ||
return false | ||
} | ||
|
||
paths := system.FindPathToFile(path, "algod.token") | ||
if len(paths) == 1 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// Checks if Algorand data directories exist, based off of existence of the "algod.token" file | ||
func deepSearchAlgorandDataDirs() []string { | ||
home, err := os.UserHomeDir() | ||
cobra.CheckErr(err) | ||
|
||
// TODO: consider a better way to identify an Algorand data directory | ||
paths := system.FindPathToFile(home, "algod.token") | ||
|
||
return paths | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"github.com/algorandfoundation/algorun-tui/internal/algod" | ||
"github.com/algorandfoundation/algorun-tui/internal/algod/utils" | ||
"github.com/algorandfoundation/algorun-tui/internal/system" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var debugCmd = &cobra.Command{ | ||
Use: "debug", | ||
Short: "Display debug information for developers", | ||
Long: "Prints debug data to be copy and pasted to a bug report.", | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
paths := utils.GetKnownDataPaths() | ||
fmt.Printf("Algod in PATH: %v\n", system.CmdExists("algod")) | ||
fmt.Printf("Algod is installed: %v\n", algod.IsInstalled()) | ||
fmt.Printf("Algod is running: %v\n", algod.IsRunning()) | ||
fmt.Printf("Algod is service: %v\n", algod.IsService()) | ||
fmt.Printf("Algod paths: %+v\n", paths) | ||
return nil | ||
}, | ||
} |
Oops, something went wrong.