Skip to content

Commit

Permalink
Merge pull request #22 from 1ed/create-php-version-file
Browse files Browse the repository at this point in the history
Add .php-version for new projects created with --php
  • Loading branch information
fabpot committed Jan 6, 2022
2 parents 0ac6b74 + 328136f commit 9572c81
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions commands/local_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ var localNewCmd = &console.Command{
return err
}

if "" != c.String("php") && !c.Bool("cloud") {
if err := createPhpVersionFile(c.String("php"), dir); err != nil {
return err
}
}

if !c.Bool("no-git") {
if _, err := exec.LookPath("git"); err == nil {
if err := initProjectGit(c, s, dir); err != nil {
Expand Down Expand Up @@ -371,3 +377,19 @@ func forcePHPVersion(v, dir string) (string, error) {
os.Setenv("FORCED_PHP_VERSION", v)
return strings.Join(strings.Split(v, ".")[0:2], "."), nil
}

func createPhpVersionFile(v, dir string) error {
file := filepath.Join(dir, ".php-version")
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return errors.Wrapf(err, "unable to create %s", file)
}
if _, err = f.WriteString(v + "\n"); err != nil {
f.Close()
return errors.Wrapf(err, "unable to write %s", file)
}
if err = f.Close(); err != nil {
return errors.Wrapf(err, "unable to close %s", file)
}
return nil
}

0 comments on commit 9572c81

Please sign in to comment.