Skip to content

Commit

Permalink
better input taking
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Singh <shubhammahar1306@gmail.com>
  • Loading branch information
1Shubham7 committed Dec 22, 2024
1 parent 5a2f6d4 commit e330ffc
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 6 deletions.
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![GitHub last commit](https://img.shields.io/github/last-commit/1shubham7/templ8)](#)
![GitHub language count](https://img.shields.io/github/languages/count/1shubham7/templ8)
![GitHub top language](https://img.shields.io/github/languages/top/1shubham7/templ8)
[![codecov](https://codecov.io/gh/1Shubham7/templ8/graph/badge.svg?token=mGg6p0S7KL)](https://codecov.io/gh/1Shubham7/templ8)

</div>

Expand Down Expand Up @@ -40,4 +41,67 @@ Whether you're starting a new project or creating a template for your team, Temp
- **Language:** Golang
- **Tools:** Cobra CLI
- **APIs:** GitHub API
- **CI Pipeline:** GitHub Actions
- **CI Pipeline:** GitHub Actions

## Installing

Follow these steps to install and set up Templ8:

1. Visit the [Releases](https://github.com/1Shubham7/templ8/releases) section of the Templ8 repository and download the latest stable release.

2. Open your shell configuration file (e.g., `~/.bashrc` or `~/.zshrc`) in a text editor:
```bash
nano ~/.bashrc
```

3. Add the following line at the end of the file to include the directory in your PATH (replace `PATH_TO_EXECUTABLE` with the actual path to your downloaded executable):
```bash
export PATH=$PATH:[PATH_TO_EXECUTABLE]
```

4. Save and close the file:
- For nano: Press `Ctrl+O`, then `Enter`, and `Ctrl+X`.

5. Reload the shell configuration:
```bash
source ~/.bashrc
```

6. Navigate to the directory where you placed the CLI executable:
```bash
cd [PATH_TO_EXECUTABLE]
```

7. Make the executable file runnable:
```bash
chmod +x templ8.exe
```

8. Verify the installation by running the following command:
```bash
templ8.exe --help
```

You're all set to transform any GitHub repository into a template! 🎉

## Usage

Simply call the executable with the URL of the repository you want to use as a template, and the tool will download the latest version of the specified branch into the directory you want and initialize it as a new repository.

```bash
templify.exe https://github.com/1Shubham7/demo-repo-for-templ8
```

### Optional Arguments

You can specify additional options such as a different branch or output directory:

- **Specify a branch:** Use the `--branch` or `-b` flag to specify a branch to clone.
- **Set an output folder:** Use the `-distination` or `-d` flag to set the name of the folder where the contents will be placed.

Example:

```bash
# This will create a folder called 'new-proj' with the contents of the source repo, specifically the 'dev' branch.
templify -b=dev -d=new-proj https://github.com/1Shubham7/demo-repo-for-templ8
```
25 changes: 20 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ Happy coding! ✨
fmt.Print(logo)
fmt.Println(cmd.Long)
if len(args) == 0 {
fmt.Println("GitHub repo is required")
fmt.Println("GitHub repo url is required")
return
}
reader := bufio.NewReader(os.Stdin)
fmt.Print("Do you want to init git? (yes/no): ")
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(strings.ToLower(input))
input := takeInput()
if input == "err" {
fmt.Println("sorry, I couldn't understand, try again with (yes/no)")
os.Exit(1)
}
CreateTemplate(args[0], branchName, input, dir)
},
}
Expand All @@ -62,6 +63,20 @@ func Execute() {
}
}

func takeInput() string {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Do you want to init git? (yes/no): ")
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(strings.ToLower(input))
if input == "yes" || input == "y" || input == "ye" || input == "yess" {
return "yes"
} else if input == "no" || input == "n" || input == "noo" {
return "no"
} else {
return "err"
}
}

func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

Expand Down

0 comments on commit e330ffc

Please sign in to comment.