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

Commit

Permalink
Merge pull request #74 from pixelandtonic/feature/prompt-when-no-conf…
Browse files Browse the repository at this point in the history
…ig-is-present

Feature/prompt when no config is present
  • Loading branch information
angrybrad authored Apr 20, 2020
2 parents 14f66eb + 08a5ea1 commit be80c3c
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 139 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Changed
- Nitro now installs the PHP SOAP extension by default.
- Nitro will now walk users through the creation of a machine when no config file is present ([#44](https://github.com/pixelandtonic/nitro/issues/44)).
- Nitro now prompts you to modify your hosts file after using `add` ([#40](https://github.com/pixelandtonic/nitro/issues/40)).

## 0.9.1 - 2020-04-18

Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,31 @@ This works like you might expect, it will create a new machine named `diesel` wi
nitro machine create
```

> Note: `nitro machine create` has options you can pass when creating a new server. However, Nitro sets some “sane” defaults by default. To view the options, run `nitro machine create --help`.
> Note: If you run `nitro machine create` and it cannot locate the `nitro.yaml` it will walk you through setting up the machine.

After running `machine create`. The bootstrap process will install the latest PHP version, MySQL, Postgres, and Redis from the `nitro.yaml` file.

The next step is to add a new virtual host to the server:
The next step is to add a new site to the machine:

```bash
nitro site add /Users/jason/Sites/craftcms myclientsite.test
cd /Users/jasonmccallister/dev
$ nitro add my-project
→ What should the hostname be? [my-project] $ myproject.test
→ Where is the webroot? [web] $
myproject.test has been added to nitro.yaml.
→ apply nitro.yaml changes now? [y] $ n
You can apply new nitro.yaml changes later by running `nitro apply`.
```

> Note: You can use any top level domain you wish, but we recomend using .test
> Note: You can use any top-level domain you wish, but we recommend using .test
This process will perform the following tasks:

1. Set up a new nginx virtual server for `myclientsite.test`.
2. Attach the directory `/Users/jason/Sites/craftcms` to that virtual server.
3. Edit your `/etc/hosts` file to point `myclientsite.test` to the virtual server for use locally.
1. Set up a new nginx virtual server for `myproject.test`.
2. Attach the directory `/Users/jasonmccallister/dev/my-project` to that virtual server.
3. Edit your `/etc/hosts` file to point `myproject.test` to the virtual server for use locally.

You can now visit `http://myclientsite.test` in your browser!
You can now visit `http://myproject.test` in your browser!

## Commands

Expand Down
28 changes: 27 additions & 1 deletion internal/cmd/add.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -177,7 +181,29 @@ var addCommand = &cobra.Command{

fmt.Println("Applied the changes and added", hostname, "to", name)

return nil
// prompt to add hosts file
cfgFile := viper.ConfigFileUsed()
if cfgFile == "" {
return errors.New("unable to find the config file")
}

filePath, err := filepath.Abs(cfgFile)
if err != nil {
return err
}

nitro, err := exec.LookPath("nitro")
if err != nil {
return err
}

fmt.Println("Modifying the hosts file to add sites for", config.GetString("name", ""), "(you will be prompted for your password)... ")

hostsCmd := exec.Command("sudo", nitro, "-f", filePath, "hosts", "add")
hostsCmd.Stdout = os.Stdout
hostsCmd.Stderr = os.Stderr

return hostsCmd.Run()
},
}

Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var contextCommand = &cobra.Command{
Use: "context",
Short: "View the current Nitro context",
Short: "View current config",
RunE: func(cmd *cobra.Command, args []string) error {
configFile := viper.ConfigFileUsed()
if configFile == "" {
Expand All @@ -27,7 +27,6 @@ var contextCommand = &cobra.Command{
fmt.Println("Using config file: ", configFile)
fmt.Println("------")
fmt.Print(string(data))
fmt.Println("------")
return nil
},
}
8 changes: 8 additions & 0 deletions internal/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,11 @@ func fileExists(filename string) bool {
}
return !info.IsDir()
}

func dirExists(dir string) bool {
info, err := os.Stat(dir)
if os.IsExist(err) {
return false
}
return info.IsDir()
}
Loading

0 comments on commit be80c3c

Please sign in to comment.