cmd/construct: get help commands working
This commit is contained in:
parent
840683528d
commit
cf85140f78
|
@ -13,6 +13,12 @@
|
|||
packages = ["."]
|
||||
revision = "b586327df9d5a5e5023fa1338f44941745136d68"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/gluanetrc"
|
||||
packages = ["."]
|
||||
revision = "af26c7928995089c19896bcc5d0f8ba48a7930a9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/gopreload"
|
||||
|
@ -965,6 +971,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "9eaa07e1d6ac7d535a05586369d4609d3930210539508423bac7cc4db97795d9"
|
||||
inputs-digest = "04d2f396a00556d6fd4651d3af551eb832ea69ff3c2ba78a5e345a494d5c2bf0"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -8,7 +8,9 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.xeserv.us/xena/route/internal/gluaroute"
|
||||
"github.com/Xe/eclier"
|
||||
"github.com/Xe/gluanetrc"
|
||||
"github.com/Xe/x/tools/glue/libs/gluaexpect"
|
||||
"github.com/Xe/x/tools/glue/libs/gluasimplebox"
|
||||
"github.com/ailncode/gluaxmlpath"
|
||||
|
@ -31,6 +33,7 @@ import (
|
|||
var hDir string
|
||||
var cfgHome *string
|
||||
var netrcFile *string
|
||||
var defaultServer *string
|
||||
|
||||
func init() {
|
||||
dir, err := homedir.Dir()
|
||||
|
@ -42,6 +45,7 @@ func init() {
|
|||
|
||||
cfgHome = flag.String("home", filepath.Join(hDir, ".construct"), "construct's home directory")
|
||||
netrcFile = flag.String("netrc", filepath.Join(hDir, ".netrc"), "location of netrc file to use for authentication")
|
||||
defaultServer = flag.String("default-server", "https://api.route.xeserv.us:7268", "api server to connect to")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -55,18 +59,22 @@ func main() {
|
|||
|
||||
os.MkdirAll(pluginLoc, 0755)
|
||||
os.MkdirAll(scriptsLoc, 0755)
|
||||
fout, err := os.Create(*netrcFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
if _, err := os.Stat(*netrcFile); err != nil {
|
||||
log.Printf("creating netrc file...")
|
||||
fout, err := os.Create(*netrcFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fout.Close()
|
||||
}
|
||||
fout.Close()
|
||||
|
||||
opts := []eclier.RouterOption{
|
||||
eclier.WithGluaCreationHook(preload),
|
||||
eclier.WithScriptHome(scriptsLoc),
|
||||
}
|
||||
|
||||
err = filepath.Walk(pluginLoc, func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(pluginLoc, func(path string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
opts = append(opts, eclier.WithScriptHome(info.Name()))
|
||||
}
|
||||
|
@ -101,4 +109,6 @@ func preload(L *lua.LState) {
|
|||
gluasimplebox.Preload(L)
|
||||
gluaxmlpath.Preload(L)
|
||||
json.Preload(L)
|
||||
gluanetrc.Preload(L)
|
||||
gluaroute.Preload(L)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package gluaroute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.xeserv.us/xena/route/proto"
|
||||
"git.xeserv.us/xena/route/proto/route"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"new": newClient,
|
||||
}
|
||||
|
||||
func newClient(L *lua.LState) int {
|
||||
routedURL := L.ToString(1)
|
||||
token := L.ToString(2)
|
||||
|
||||
L.Push(luar.New(L, route.New(routedURL, token, &http.Client{})))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
type client struct {
|
||||
*route.Client
|
||||
}
|
||||
|
||||
type backends struct {
|
||||
proto.Backends
|
||||
}
|
||||
|
||||
type routes struct {
|
||||
proto.Routes
|
||||
}
|
||||
|
||||
type tokens struct {
|
||||
proto.Tokens
|
||||
}
|
||||
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("svc", Loader)
|
||||
}
|
||||
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
2
mage.go
2
mage.go
|
@ -177,8 +177,6 @@ func Tools(ctx context.Context) {
|
|||
func Generate(ctx context.Context) {
|
||||
dir := filepath.Join(wd, "proto")
|
||||
|
||||
Tools(ctx)
|
||||
|
||||
shouldWork(ctx, nil, dir, "sh", "./regen.sh")
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.backends.kill(flags)
|
||||
local resp = svc.new(apiURL, token):backends():kill(flags)
|
||||
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.backends.list(flags)
|
||||
local resp = svc.new(apiURL, token):backends():list(flags)
|
||||
|
||||
print("bs:\t\t" .. tostring(resp.bs))
|
||||
print("backends:\t\t" .. tostring(resp.backends))
|
||||
|
|
|
@ -28,6 +28,6 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.routes.delete(flags)
|
||||
local resp = svc.new(apiURL, token):routes():delete(flags)
|
||||
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.routes.get(flags)
|
||||
local resp = svc.new(apiURL, token):routes():get(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("creator:\t\t" .. tostring(resp.creator))
|
||||
|
|
|
@ -25,7 +25,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.routes.get_all(flags)
|
||||
local resp = svc.new(apiURL, token):routes():get_all(flags)
|
||||
|
||||
print("routes:\t\t" .. tostring(resp.routes))
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.routes.put(flags)
|
||||
local resp = svc.new(apiURL, token):routes():put(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("creator:\t\t" .. tostring(resp.creator))
|
||||
|
|
|
@ -13,10 +13,10 @@ local svc = require "svc"
|
|||
local fs = flag.new()
|
||||
|
||||
-- flags for Token
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("body", "", "value for message arg body")
|
||||
fs:strings("scopes", "", "value for message arg scopes")
|
||||
fs:bool("active", "", "value for message arg active")
|
||||
fs:strings("scopes", "value for message arg scopes")
|
||||
fs:bool("active", false, "value for message arg active")
|
||||
fs:string("id", "", "value for message arg id")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
|
@ -29,6 +29,6 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.tokens.deactivate(flags)
|
||||
local resp = svc.new(apiURL, token):tokens():deactivate(flags)
|
||||
|
||||
end
|
||||
|
|
|
@ -13,10 +13,10 @@ local svc = require "svc"
|
|||
local fs = flag.new()
|
||||
|
||||
-- flags for Token
|
||||
fs:strings("scopes", "value for message arg scopes")
|
||||
fs:bool("active", false, "value for message arg active")
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("body", "", "value for message arg body")
|
||||
fs:strings("scopes", "", "value for message arg scopes")
|
||||
fs:bool("active", "", "value for message arg active")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
|
@ -29,6 +29,6 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.tokens.delete(flags)
|
||||
local resp = svc.new(apiURL, token):tokens():delete(flags)
|
||||
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.tokens.get(flags)
|
||||
local resp = svc.new(apiURL, token):tokens():get(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("body:\t\t" .. tostring(resp.body))
|
||||
|
|
|
@ -25,7 +25,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.tokens.get_all(flags)
|
||||
local resp = svc.new(apiURL, token):tokens():get_all(flags)
|
||||
|
||||
print("tokens:\t\t" .. tostring(resp.tokens))
|
||||
end
|
||||
|
|
|
@ -13,10 +13,10 @@ local svc = require "svc"
|
|||
local fs = flag.new()
|
||||
|
||||
-- flags for Token
|
||||
fs:bool("active", false, "value for message arg active")
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("body", "", "value for message arg body")
|
||||
fs:strings("scopes", "", "value for message arg scopes")
|
||||
fs:bool("active", "", "value for message arg active")
|
||||
fs:strings("scopes", "value for message arg scopes")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
|
@ -29,7 +29,7 @@ function run(arg)
|
|||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.tokens.put(flags)
|
||||
local resp = svc.new(apiURL, token):tokens():put(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("body:\t\t" .. tostring(resp.body))
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2017 Christine Dodrill <me@christine.website>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,7 @@
|
|||
file = {
|
||||
"./netrc.lua",
|
||||
}
|
||||
|
||||
title = "gluanetrc"
|
||||
project = "Xe/gluanetrc"
|
||||
description = "netrc offers a simple interface to a user's netrc file in their home directory"
|
|
@ -0,0 +1,81 @@
|
|||
package gluanetrc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/dickeyxxx/netrc"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
var n *netrc.Netrc
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
fname := filepath.Join(os.Getenv("HOME"), ".netrc")
|
||||
|
||||
fout, err := os.Create(fname)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fout.Close()
|
||||
|
||||
n, err = netrc.Parse(filepath.Join(fname))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"machine": machine,
|
||||
"save": save,
|
||||
"remove_machine": removeMachine,
|
||||
"add_machine": addMachine,
|
||||
}
|
||||
|
||||
func addMachine(L *lua.LState) int {
|
||||
name := L.ToString(1)
|
||||
login := L.ToString(2)
|
||||
password := L.ToString(3)
|
||||
|
||||
n.AddMachine(name, login, password)
|
||||
|
||||
L.Push(luar.New(L, n.Machine(name)))
|
||||
return 1
|
||||
}
|
||||
|
||||
func removeMachine(L *lua.LState) int {
|
||||
name := L.ToString(1)
|
||||
|
||||
n.RemoveMachine(name)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func machine(L *lua.LState) int {
|
||||
name := L.ToString(1)
|
||||
|
||||
m := n.Machine(string(name))
|
||||
|
||||
L.Push(luar.New(L, m))
|
||||
return 1
|
||||
}
|
||||
|
||||
func save(L *lua.LState) int {
|
||||
n.Save()
|
||||
return 0
|
||||
}
|
||||
|
||||
// Preload loads netrc into a gopher-lua's LState module registry.
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("netrc", Loader)
|
||||
}
|
||||
|
||||
// Loader loads the netrc modules.
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
--- Module netrc offers a simple interface to a user's netrc file in their home directory.
|
||||
-- @module netrc
|
||||
|
||||
local netrc = {}
|
||||
|
||||
--- add_machine adds a machine to the netrc manifest with a username and password.
|
||||
-- @param name string the domain name of the machine
|
||||
-- @param login string the user name to log in as
|
||||
-- @param password string the password or similar secret for the machine
|
||||
-- @return Machine
|
||||
function netrc.add_machine(name, login, password)
|
||||
end
|
||||
|
||||
--- machine loads netrc data for a given machine by domain name.
|
||||
-- Any changes made with the `set` method of a machine will be saved to the disk
|
||||
-- when the module's `save` function is called. If the given machine does not
|
||||
-- exist in the netrc file, this function will return nil.
|
||||
-- @param name string
|
||||
-- @return Machine
|
||||
-- @usage local creds = netrc.machine("api.foobar.com")
|
||||
-- @usage print(creds:get("username"), creds:get("password"))
|
||||
function netrc.machine(name)
|
||||
return nil
|
||||
end
|
||||
|
||||
--- remove_machine removes a single machine from the netrc manifest by name.
|
||||
-- @param name string the name of the machine to remove from the netrc manifest
|
||||
-- @usage netrc.remove_machine("api.digg.com")
|
||||
function netrc.remove_machine(name)
|
||||
end
|
||||
|
||||
--- save writes all changes made in machine `set` methods to the disk at $HOME/.netrc.
|
||||
-- This function will raise a lua error if the save fails. This function should
|
||||
-- not fail in the course of normal operation.
|
||||
-- @usage netrc.save()
|
||||
function netrc.save()
|
||||
end
|
||||
|
||||
--- Machine is a userdata wrapper around the go netrc.Machine type.
|
||||
-- https://godoc.org/github.com/dickeyxxx/netrc#Machine
|
||||
-- @type Machine
|
||||
|
||||
local Machine = {}
|
||||
|
||||
--- get gets a Machine value by key.
|
||||
-- @param key the netrc key to get
|
||||
-- @return string the value from the netrc
|
||||
-- @usage local cli = api.new(m:get("login"), m:get("password"))
|
||||
function Machine:get(key)
|
||||
end
|
||||
|
||||
--- set updates information in this Machine by a key, value pair.
|
||||
-- @param key the netrc key to set
|
||||
-- @param value the value to set the above key to
|
||||
-- @usage m:set("password", "hunter2")
|
||||
function Machine:set(key, value)
|
||||
end
|
||||
|
||||
return netrc
|
Loading…
Reference in New Issue