-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for running code snippets in addition to named commands
- Resolves #3 - Adds support for perl, python, js, ruby code snippets
- Loading branch information
1 parent
88d2b14
commit d8994ed
Showing
10 changed files
with
158 additions
and
45 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
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 |
---|---|---|
@@ -1,22 +1,11 @@ | ||
package model | ||
|
||
import "fmt" | ||
|
||
// Code container for snippet | ||
type Code struct { | ||
Language string `json:"language"` | ||
Snippet string `json:"snippet"` | ||
} | ||
|
||
// executionString for execution translated from code snippet and language | ||
func (c *Code) executionString() (string, error) { | ||
switch c.Language { | ||
case "ruby": | ||
return fmt.Sprintf("ruby -e '%s'", c.Snippet), nil | ||
case "python": | ||
return fmt.Sprintf("python -c '%s'", c.Snippet), nil | ||
case "shell": | ||
return fmt.Sprintf("sh -c %s", c.Snippet), nil | ||
} | ||
return "", fmt.Errorf("unsupported language for code snippet: %s", c.Language) | ||
func (c *Code) valid() bool { | ||
return len(c.Snippet) > 0 && len(c.Language) > 0 | ||
} |
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
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
Oops, something went wrong.