mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-22 18:30:43 -06:00
feat: oizys update
This commit is contained in:
parent
c5a38b7506
commit
3e38f187dd
5 changed files with 69 additions and 18 deletions
|
@ -12,15 +12,8 @@ var dryCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var verbose bool
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(dryCmd)
|
rootCmd.AddCommand(dryCmd)
|
||||||
dryCmd.Flags().BoolVarP(
|
|
||||||
&verbose,
|
|
||||||
"verbose",
|
|
||||||
"v",
|
|
||||||
false,
|
|
||||||
"show verbose output",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ func Execute() {
|
||||||
cc.Init(&cc.Config{
|
cc.Init(&cc.Config{
|
||||||
RootCmd: rootCmd,
|
RootCmd: rootCmd,
|
||||||
Headings: cc.HiMagenta + cc.Bold,
|
Headings: cc.HiMagenta + cc.Bold,
|
||||||
Commands: cc.HiYellow + cc.Bold,
|
Commands: cc.Bold,
|
||||||
Example: cc.Italic,
|
Example: cc.Italic,
|
||||||
ExecName: cc.HiYellow + cc.Bold,
|
ExecName: cc.Bold,
|
||||||
Flags: cc.Bold,
|
Flags: cc.Bold,
|
||||||
NoExtraNewlines: true,
|
NoExtraNewlines: true,
|
||||||
NoBottomNewline: true,
|
NoBottomNewline: true,
|
||||||
|
@ -29,6 +29,7 @@ var (
|
||||||
flake string
|
flake string
|
||||||
host string
|
host string
|
||||||
cacheName string
|
cacheName string
|
||||||
|
verbose bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var oizys = o.NewOizys()
|
var oizys = o.NewOizys()
|
||||||
|
@ -37,7 +38,7 @@ var rootCmd = &cobra.Command{
|
||||||
Use: "oizys",
|
Use: "oizys",
|
||||||
Short: "nix begat oizys",
|
Short: "nix begat oizys",
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
oizys.Update(flake, host, cacheName)
|
oizys.Update(flake, host, cacheName, verbose)
|
||||||
oizys.CheckFlake()
|
oizys.CheckFlake()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -46,4 +47,5 @@ func init() {
|
||||||
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||||
rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)")
|
rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)")
|
||||||
rootCmd.PersistentFlags().StringVar(&host, "host", "", "host to build (current host)")
|
rootCmd.PersistentFlags().StringVar(&host, "host", "", "host to build (current host)")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
|
||||||
}
|
}
|
||||||
|
|
20
pkgs/oizys/oizys-go/cmd/update.go
Normal file
20
pkgs/oizys/oizys-go/cmd/update.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var updateCmd = &cobra.Command{
|
||||||
|
Use: "update",
|
||||||
|
Short: "update and run nixos rebuild",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
oizys.GitPull()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var boot bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(updateCmd)
|
||||||
|
updateCmd.Flags().BoolVarP(&boot, "boot", "b", false, "run nixos-rebuild boot")
|
||||||
|
}
|
|
@ -18,9 +18,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Oizys struct {
|
type Oizys struct {
|
||||||
flake string
|
flake string
|
||||||
host string
|
host string
|
||||||
cache string
|
cache string
|
||||||
|
verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = termenv.NewOutput(os.Stdout)
|
var output = termenv.NewOutput(os.Stdout)
|
||||||
|
@ -50,7 +51,7 @@ func (o *Oizys) Output() string {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Oizys) Update(flake string, host string, cache string) {
|
func (o *Oizys) Update(flake string, host string, cache string, verbose bool) {
|
||||||
if host != "" {
|
if host != "" {
|
||||||
o.host = host
|
o.host = host
|
||||||
}
|
}
|
||||||
|
@ -60,6 +61,7 @@ func (o *Oizys) Update(flake string, host string, cache string) {
|
||||||
if cache != "" {
|
if cache != "" {
|
||||||
o.cache = cache
|
o.cache = cache
|
||||||
}
|
}
|
||||||
|
o.verbose = verbose
|
||||||
}
|
}
|
||||||
|
|
||||||
func terminalSize() (int, int) {
|
func terminalSize() (int, int) {
|
||||||
|
@ -137,13 +139,48 @@ func (p *packages) summary() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Oizys) git(rest ...string) *exec.Cmd {
|
||||||
|
args := []string{"-C", o.flake}
|
||||||
|
args = append(args, rest...)
|
||||||
|
if o.verbose {
|
||||||
|
fmt.Println("CMD:", "git", strings.Join(args, " "))
|
||||||
|
}
|
||||||
|
return exec.Command("git", args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func showFailedOutput(buf []byte) {
|
||||||
|
arrow := output.String("->").Bold().Foreground(output.Color("9"))
|
||||||
|
for _, line := range strings.Split(strings.TrimSpace(string(buf)), "\n") {
|
||||||
|
fmt.Println(arrow, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Oizys) GitPull() {
|
||||||
|
|
||||||
|
cmdOutput, err := o.git("status", "--porcelain").Output()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cmdOutput) > 0 {
|
||||||
|
fmt.Println("unstaged commits, cowardly exiting...")
|
||||||
|
showFailedOutput(cmdOutput)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmdOutput, err := o.git("pull").CombinedOutput(); err != nil {
|
||||||
|
showFailedOutput(cmdOutput)
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ParseDryRunOutput(nixOutput string, verbose bool) {
|
func ParseDryRunOutput(nixOutput string, verbose bool) {
|
||||||
parts := strings.Split("\n" + nixOutput, "\nthese")
|
parts := strings.Split("\n"+nixOutput, "\nthese")
|
||||||
|
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
log.Println("no changes...")
|
log.Println("no changes...")
|
||||||
log.Println("or I failed to parse it into the expected number of parts")
|
log.Println("or I failed to parse it into the expected number of parts")
|
||||||
fmt.Println(parts)
|
fmt.Println(parts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
toBuild := parsePackages(parts[1], "packages to build")
|
toBuild := parsePackages(parts[1], "packages to build")
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -1,6 +1,5 @@
|
||||||
# oizys todo's
|
# oizys todo's
|
||||||
|
|
||||||
- [ ] add `oizys update` to pull changes and run `oizys switch`
|
|
||||||
- [ ] go back to latest kernel when VirtualBox Upgrade is merged
|
- [ ] go back to latest kernel when VirtualBox Upgrade is merged
|
||||||
|
|
||||||
<!-- generated with <3 by daylinmorgan/todo -->
|
<!-- generated with <3 by daylinmorgan/todo -->
|
||||||
|
|
Loading…
Reference in a new issue