Browse Source

Add config

Brett Langdon 9 years ago
parent
commit
034ab86faf
No known key found for this signature in database GPG Key ID: A2ECAB73CE12147F
3 changed files with 57 additions and 2 deletions
  1. +8
    -2
      cmd/pypihub/main.go
  2. +35
    -0
      config.go
  3. +14
    -0
      utils.go

+ 8
- 2
cmd/pypihub/main.go View File

@ -1,7 +1,13 @@
package main
import "fmt"
import (
"fmt"
"github.com/brettlangdon/pypihub"
)
func main() {
fmt.Println("PyPIHub")
var config pypihub.Config
config = pypihub.ParseConfig()
fmt.Printf("%#v\r\n", config)
}

+ 35
- 0
config.go View File

@ -0,0 +1,35 @@
package pypihub
import (
"os"
"strings"
arg "github.com/alexflint/go-arg"
)
type Config struct {
Username string `arg:"-u,--username,env:PYPIHUB_USERNAME,required,help:Username of GitHub user to login as (env: PYPIHUB_USERNAME)"`
AccessToken string `arg:"-a,--access-token,env:PYPIHUB_ACCESS_TOKEN,required,help:GitHub personal access token to use for authenticating (env: PYPIHUB_ACCESS_TOKEN)"`
RepoNames []string `arg:"positional,help:list of '<username>/<repo>' repos to proxy for (env: PYPIHUB_REPOS)"`
Bind string `arg:"-b,--bind,env:PYPIHUB_BIND,help:[<address>]:<port> to bind the server to (default: ':8287') (env: PYPIHUB_BIND)"`
}
func ParseConfig() Config {
var config = Config{
Bind: ":8287",
RepoNames: make([]string, 0),
}
arg.MustParse(&config)
if val, ok := os.LookupEnv("PYPIHUB_REPOS"); ok {
config.RepoNames = append(config.RepoNames, strings.Split(val, " ")...)
}
for i := range config.RepoNames {
config.RepoNames[i] = strings.Trim(config.RepoNames[i], " ")
}
config.RepoNames = uniqueSlice(config.RepoNames)
return config
}

+ 14
- 0
utils.go View File

@ -0,0 +1,14 @@
package pypihub
func uniqueSlice(s []string) []string {
var m = make(map[string]bool)
for _, v := range s {
m[v] = true
}
var o = make([]string, 0)
for v := range m {
o = append(o, v)
}
return o
}

Loading…
Cancel
Save