-
Notifications
You must be signed in to change notification settings - Fork 24
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
12 changed files
with
172 additions
and
77 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ryanuber/columnize" | ||
) | ||
|
||
func printTable(rows []string) { | ||
|
||
table := columnize.SimpleFormat(rows) | ||
|
||
fmt.Println() | ||
fmt.Println(table) | ||
fmt.Println() | ||
} | ||
|
||
func yesNo(isTrue bool) string { | ||
if isTrue { | ||
return "yes" | ||
} | ||
return "" | ||
} |
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 +1,14 @@ | ||
package command | ||
|
||
type testCase struct { | ||
Input string | ||
Output map[string]string | ||
} | ||
|
||
type parserConfig struct { | ||
Name string | ||
Description string | ||
Tests []testCase | ||
Example string | ||
Script string | ||
} |
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 +1,51 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
|
||
"github.com/shurcooL/graphql" | ||
"golang.org/x/oauth2" | ||
cli "gopkg.in/urfave/cli.v2" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
func ParserGet(c *cli.Context) error { | ||
config, _ := getServerConfig(c) | ||
|
||
ensureToken(config) | ||
ensureRepo(config) | ||
ensureURL(config) | ||
|
||
parserName := c.Args().First() | ||
|
||
src := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: config.Token}, | ||
) | ||
|
||
httpClient := oauth2.NewClient(context.Background(), src) | ||
client := graphql.NewClient(config.URL+"graphql", httpClient) | ||
|
||
var q struct { | ||
Repository struct { | ||
Parser struct { | ||
SourceCode string | ||
} `graphql:"parser(name: $parserName)"` | ||
} `graphql:"repository(name: $repositoryName)"` | ||
} | ||
|
||
variables := map[string]interface{}{ | ||
"parserName": graphql.String(parserName), | ||
"repositoryName": graphql.String(config.Repo), | ||
} | ||
|
||
graphqlErr := client.Query(context.Background(), &q, variables) | ||
check(graphqlErr) | ||
|
||
d, yamlErr := yaml.Marshal(&q) | ||
check(yamlErr) | ||
|
||
ioutil.WriteFile(parserName+".yaml", d, 0644) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/shurcooL/graphql" | ||
cli "gopkg.in/urfave/cli.v2" | ||
) | ||
|
||
func UsersShow(c *cli.Context) error { | ||
config, _ := getServerConfig(c) | ||
|
||
ensureToken(config) | ||
ensureURL(config) | ||
|
||
username := c.Args().First() | ||
|
||
var q struct { | ||
Account struct { | ||
Username string | ||
FullName string | ||
IsRoot bool | ||
CreatedAt string | ||
} `graphql:"account(username: $username)"` | ||
} | ||
|
||
variables := map[string]interface{}{ | ||
"username": graphql.String(username), | ||
} | ||
|
||
graphqlErr := newGraphQLClient(config).Query(context.Background(), &q, variables) | ||
check(graphqlErr) | ||
|
||
userData := []string{q.Account.Username, q.Account.FullName, q.Account.CreatedAt, yesNo(q.Account.IsRoot)} | ||
|
||
printTable([]string{ | ||
"Username | Name | Created At | Is Root", | ||
strings.Join(userData, "|"), | ||
}) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package command | ||
|
||
import "log" | ||
|
||
func check(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.