-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from WillAbides/breakupmain
break up main into separate files
- Loading branch information
Showing
4 changed files
with
105 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
|
||
"github.com/alecthomas/kong" | ||
"github.com/willabides/bindownloader" | ||
) | ||
|
||
var configKongVars = kong.Vars{ | ||
"config_format_help": `formats the config file`, | ||
"config_checksums_help": `update checksums in the config file`, | ||
} | ||
|
||
type configCmd struct { | ||
Format configFmtCmd `kong:"cmd,help=${config_format_help}"` | ||
} | ||
|
||
type configFmtCmd struct{} | ||
|
||
func (c configFmtCmd) Run() error { | ||
config, err := bindownloader.LoadConfigFile(cli.Configfile) | ||
if err != nil { | ||
return err | ||
} | ||
b, err := json.MarshalIndent(&config, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
return ioutil.WriteFile(cli.Configfile, b, 0600) | ||
} |
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"runtime" | ||
|
||
"github.com/alecthomas/kong" | ||
"github.com/willabides/bindownloader" | ||
) | ||
|
||
var downloadKongVars = kong.Vars{ | ||
"download_arch_help": `download for this architecture`, | ||
"download_arch_default": runtime.GOARCH, | ||
"download_os_help": `download for this operating system`, | ||
"download_os_default": runtime.GOOS, | ||
"download_force_help": `force download even if it already exists`, | ||
"download_target_file_help": `file to download`, | ||
} | ||
|
||
type downloadCmd struct { | ||
Arch string `kong:"help=${download_arch_help},default=${download_arch_default}"` | ||
OS string `kong:"help=${download_os_help},default=${download_os_default}"` | ||
Force bool `kong:"help=${download_force_help}"` | ||
TargetFile string `kong:"required=true,arg,help=${download_target_file_help}"` | ||
} | ||
|
||
func (d *downloadCmd) Run(*kong.Context) error { | ||
config, err := bindownloader.LoadConfigFile(cli.Configfile) | ||
if err != nil { | ||
return fmt.Errorf("error loading config from %q", cli.Configfile) | ||
} | ||
binary := path.Base(d.TargetFile) | ||
binDir := path.Dir(d.TargetFile) | ||
|
||
downloader := config.Downloader(binary, d.OS, d.Arch) | ||
if downloader == nil { | ||
return fmt.Errorf(`no downloader configured for: | ||
bin: %s | ||
os: %s | ||
arch: %s`, binary, d.OS, d.Arch) | ||
} | ||
|
||
installOpts := bindownloader.InstallOpts{ | ||
DownloaderName: binary, | ||
TargetDir: binDir, | ||
Force: d.Force, | ||
CellarDir: cli.CellarDir, | ||
} | ||
|
||
return downloader.Install(installOpts) | ||
} |
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,14 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/alecthomas/kong" | ||
) | ||
|
||
var version = "unknown" | ||
|
||
type versionCmd struct{} | ||
|
||
func (*versionCmd) Run(k *kong.Context) error { | ||
k.Printf("version %s", version) | ||
return nil | ||
} |