Skip to content

Commit d69b1f0

Browse files
committed
[feat] Add php.ini editing option
1 parent 50b1bb2 commit d69b1f0

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,23 @@ Currently supported PHP versions are:
2424
8.1
2525
8.2
2626

27-
# Contributing
27+
### Editing php.ini file
28+
29+
You can edit the php.ini file for the current PHP version by running the following command:
30+
31+
```cmd
32+
php-ch ini
33+
```
34+
35+
### Editing php.ini file for a specific PHP version
36+
37+
You can edit the php.ini file for a specific PHP version by running the following command:
38+
39+
```cmd
40+
php-ch ini [version]
41+
```
42+
43+
## Contributing
2844

2945
Feel free to open an issue or a pull request if you have any suggestions or bug reports.
3046

cmd/ch/ini.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package ch
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
7+
"github.com/BrainBuzzer/php-ch/pkg"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var iniCommand = &cobra.Command{
12+
Use: "ini",
13+
Short: "Edit php.ini file",
14+
Long: `Edit php.ini file`,
15+
Args: func(cmd *cobra.Command, args []string) error {
16+
if len(args) > 1 {
17+
return fmt.Errorf("too many arguments")
18+
} else if len(args) == 1 {
19+
switch args[0] {
20+
case "7.4", "8.0", "8.1", "8.2":
21+
return nil
22+
default:
23+
return fmt.Errorf("invalid version: %s", args[0])
24+
}
25+
}
26+
return nil
27+
},
28+
Run: func(cmd *cobra.Command, args []string) {
29+
exepath := "C:\\Windows\\system32\\notepad.exe"
30+
31+
defaultIniPath := "C:\\Program Files\\php\\php.ini"
32+
if len(args) == 1 {
33+
// open php.ini of specific version
34+
iniPath := pkg.GetVersionPath(args[0]) + "\\php.ini"
35+
err := exec.Command(exepath, iniPath).Run()
36+
if err != nil {
37+
fmt.Println(err)
38+
}
39+
}
40+
41+
// open default php.ini
42+
err := exec.Command(exepath, defaultIniPath).Run()
43+
if err != nil {
44+
fmt.Println(err)
45+
}
46+
},
47+
}
48+
49+
func init() {
50+
rootCmd.AddCommand(iniCommand)
51+
}

pkg/versions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func DownloadVersion(version string) {
7070
}
7171
}
7272

73+
func GetVersionPath(version string) string {
74+
return filepath.Join(env.Root, "versions", version)
75+
}
76+
7377
func downloadAndInstall(url string, version string) {
7478
req, _ := http.NewRequest("GET", url, nil)
7579
resp, _ := http.DefaultClient.Do(req)

0 commit comments

Comments
 (0)