-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for custom commands #265
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7fa774b
Adds support for custom commands
mntn-xyz e9fecac
Merge changes from master
mntn-xyz e797ce2
Merge branch 'master' into commands
mntn-xyz cf07d9e
Merge branch 'master' into commands
mntn-xyz 4c85e1e
Fix linting issues
mntn-xyz ea7e024
Fix typo
mntn-xyz 5ecc1a3
Merge branch 'master' into commands
mntn-xyz 96add16
Merge branch 'master' into commands
mntn-xyz 416f4b3
Merge branch 'commands' of github.com:mntn-xyz/amfora into commands
mntn-xyz 774554a
Further clarify comment
mntn-xyz f13018b
Use goroutines for Error/Info calls
mntn-xyz 3b3d774
Merge branch 'master' into commands
mntn-xyz 1a5ea27
Run go fmt to fix issue from merge
mntn-xyz 97b5c44
Merge branch 'master' into commands
makew0rld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 @@ | ||
package command | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
// RunCommand runs `command`, replacing the string "${url}" with `url`. | ||
func RunCommand(command string, url string) (string, error) { | ||
cmdWithURL := strings.ReplaceAll(command, "${url}", url) | ||
cmdSplit := strings.SplitN(cmdWithURL, " ", 2) | ||
if len(cmdSplit) > 1 { | ||
if err := exec.Command(cmdSplit[0], cmdSplit[1]).Start(); err != nil { | ||
return "", err | ||
} | ||
return "Ran command " + cmdSplit[0] + " with args " + cmdSplit[1], nil | ||
} | ||
if err := exec.Command(cmdWithURL).Start(); err != nil { | ||
return "", err | ||
} | ||
return "Ran command " + cmdWithURL, nil | ||
} |
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
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
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,35 @@ | ||
package display | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/makeworld-the-better-one/amfora/command" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// CustomCommand runs custom commands as defined in the app configuration. | ||
// Commands are zero-indexed, so 0 is command1 and 9 is command0 (10). | ||
func CustomCommand(num int, url string) { | ||
if num < 0 { | ||
num = 0 | ||
} | ||
num++ | ||
if num > 9 { | ||
num = 0 | ||
} | ||
|
||
cmd := viper.GetString("commands.command" + strconv.Itoa(num)) | ||
if len(cmd) > 0 { | ||
msg, err := command.RunCommand(cmd, url) | ||
if err != nil { | ||
go Error("Command Error", err.Error()) | ||
return | ||
} | ||
go Info(msg) | ||
} else { | ||
go Error("Command Error", "Command "+strconv.Itoa(num)+" not defined") | ||
return | ||
} | ||
|
||
App.Draw() | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a simple split like this will fail on commands with quoted strings. It might be better to use go-shellquote or something else.