-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
--create-repo
, --repo-name
and --private
flags to new
cmd
- Loading branch information
Showing
4 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package new | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
|
||
"github.com/abdfnx/botway/internal/options" | ||
) | ||
|
||
func createRepoWindows(botName string, isPrivate bool) string { | ||
privateFlag := "" | ||
|
||
if isPrivate { | ||
privateFlag = "--private" | ||
} | ||
|
||
return fmt.Sprintf(` | ||
$username = botway gh get-username | ||
git init | ||
botway gh-repo create %s -d "My Awesome bot" %s -y | ||
git add . | ||
git commit -m "new botway bot project" | ||
git branch -M main | ||
git push -u origin main | ||
`, botName, privateFlag) | ||
} | ||
|
||
func createRepoUnix(botName string, isPrivate bool) string { | ||
repoStatus := "--public" | ||
|
||
if isPrivate { | ||
repoStatus = "--private" | ||
} | ||
|
||
return fmt.Sprintf(` | ||
username=$(botway gh get-username) | ||
git init | ||
botway gh-repo create %s -d "My Awesome bot" %s -y | ||
git add . | ||
git commit -m "new botway bot project" | ||
git branch -M main | ||
git push -u origin main | ||
`, botName, repoStatus) | ||
} | ||
|
||
func CreateRepo(o *options.NewOptions, botName string) { | ||
if o.RepoName == "" { | ||
o.RepoName = botName | ||
} | ||
|
||
createRepoCmd := exec.Command("bash", "-c", createRepoUnix(o.RepoName, o.IsPrivate)) | ||
|
||
if runtime.GOOS == "windows" { | ||
createRepoCmd = exec.Command("powershell.exe", "-Command", createRepoWindows(o.RepoName, o.IsPrivate)) | ||
} | ||
|
||
createRepoCmd.Dir = botName | ||
createRepoCmd.Stdin = os.Stdin | ||
createRepoCmd.Stdout = os.Stdout | ||
createRepoCmd.Stderr = os.Stderr | ||
err := createRepoCmd.Run() | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
} | ||
} |