Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
working on issues with windows and hosts editing
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccallister committed May 27, 2020
1 parent 979275c commit 7af9395
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
9 changes: 1 addition & 8 deletions internal/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"os/exec"
"runtime"
"strings"

"github.com/spf13/cobra"
Expand All @@ -12,7 +11,6 @@ import (
"github.com/craftcms/nitro/config"
"github.com/craftcms/nitro/internal/find"
"github.com/craftcms/nitro/internal/nitro"
"github.com/craftcms/nitro/internal/runas"
"github.com/craftcms/nitro/internal/scripts"
"github.com/craftcms/nitro/internal/task"
"github.com/craftcms/nitro/internal/webroot"
Expand Down Expand Up @@ -125,12 +123,7 @@ var applyCommand = &cobra.Command{
return nil
}

// if this is windows, its always root - we should clean this up eventually
if runtime.GOOS == "windows" {
return hostsCommand.RunE(cmd, args)
}

return runas.Elevated(machine, []string{"hosts"})
return hostsCommand.RunE(cmd, args)
},
}

Expand Down
13 changes: 1 addition & 12 deletions internal/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"time"

Expand All @@ -19,7 +18,6 @@ import (
"github.com/craftcms/nitro/datetime"
"github.com/craftcms/nitro/internal/helpers"
"github.com/craftcms/nitro/internal/nitro"
"github.com/craftcms/nitro/internal/runas"
"github.com/craftcms/nitro/internal/scripts"
)

Expand Down Expand Up @@ -209,18 +207,9 @@ var destroyCommand = &cobra.Command{
return nil
}

cmds := []string{"hosts", "remove"}
for _, domain := range domains {
cmds = append(cmds, domain)
}

fmt.Println("Removing sites from your hosts file.")

if runtime.GOOS == "windows" {
return hostsRemoveCommand.RunE(cmd, cmds)
}

return runas.Elevated(machine, cmds)
return hostsRemoveCommand.RunE(cmd, domains)
},
}

Expand Down
11 changes: 9 additions & 2 deletions internal/cmd/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package cmd
import (
"errors"
"fmt"
"os"

"github.com/craftcms/nitro/internal/runas"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/txn2/txeh"
"os"
"runtime"

"github.com/craftcms/nitro/config"
"github.com/craftcms/nitro/internal/hosts"
Expand All @@ -21,6 +22,12 @@ var hostsCommand = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
machine := flagMachineName

if runtime.GOOS != "windows" {
if err := runas.Elevated(machine, args); err != nil {
return err
}
}

if !flagDebug {
uid := os.Geteuid()
if (uid != 0) && (uid != -1) {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/hosts_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var hostsRemoveCommand = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
if !flagDebug {
uid := os.Geteuid()
if uid != 0 {
if (uid != 0) && (uid != -1) {
return errors.New("you do not appear to be running this command as root, so we cannot modify your hosts file")
}
}
Expand Down
11 changes: 2 additions & 9 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/craftcms/nitro/config"
"github.com/craftcms/nitro/internal/nitro"
"github.com/craftcms/nitro/internal/runas"
"github.com/craftcms/nitro/internal/suggest"
"github.com/craftcms/nitro/validate"
)
Expand Down Expand Up @@ -229,14 +228,8 @@ var initCommand = &cobra.Command{

// if there are sites, edit the hosts file
if len(sites) > 0 {
if runtime.GOOS == "windows" {
if err := hostsCommand.RunE(cmd, args); err != nil {
fmt.Println("Unable to edit the hosts file, please edit it manually or run `nitro apply`")
}
} else {
if err := runas.Elevated(machine, []string{"hosts"}); err != nil {
fmt.Println("Unable to edit the hosts file, please edit it manually or run `nitro apply`")
}
if err := hostsCommand.RunE(cmd, args); err != nil {
return err
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var removeCommand = &cobra.Command{
}
// END HACK

applyChanges, err := p.Confirm("Apply changes from config now", &prompt.InputOptions{
apply, err := p.Confirm("Apply changes from config now", &prompt.InputOptions{
Default: "yes",
Validator: nil,
AppendQuestionMark: true,
Expand All @@ -91,7 +91,7 @@ var removeCommand = &cobra.Command{
return err
}

if applyChanges {
if apply {
fmt.Println("Applying changes from the config file...")
return applyCommand.RunE(cmd, args)
}
Expand Down

0 comments on commit 7af9395

Please # to comment.