Skip to content

Commit

Permalink
Implemented generate command ✨ (#3)
Browse files Browse the repository at this point in the history
* Added cobra 🐍

* Deleted trash :trash:

* Added tests ✅

* Added docs and lint

* Making the lint happy

* added generate and remote commands

* making lint happy

* added properties to commands

* added arguments and flags to generate

* file copy for generate

* making linter happy
  • Loading branch information
EmperorYP7 authored Mar 5, 2021
1 parent 13b0ad5 commit 23a8d23
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: go test -race ./...

- name: Build
run: go build -v ./...
run: go build

build-minimum:
runs-on: ubuntu-latest
Expand All @@ -41,4 +41,4 @@ jobs:
- name: Build
env:
CGO_ENABLED: '0'
run: go build -v ./...
run: go build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ tmake
.vscode
main
.DS_Store
.idea
22 changes: 12 additions & 10 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,29 @@ import (

// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate",
Aliases: []string{},
SuggestFor: []string{},
Use: "generate [-d Destination] [args]",
Aliases: []string{"gen"},
SuggestFor: []string{"genrate", "make", "create"},
Short: "Lets you generate templates",
Long: `
The command lets you generate templates based on remote or local
sources if they're valid otherwise, will throw an error.
`,
Example: "tmake generate [sub-commands] -flags=value",
ValidArgs: []string{},
// Args: func(cmd *cobra.Command, args []string) error {
// },
Example: "tmake generate 5 templatename1 ./CodeForces-697",
Args: cobra.MinimumNArgs(2),
ArgAliases: []string{},
BashCompletionFunction: "",
BashCompletionFunction: "generate",
Deprecated: "",
Hidden: false,
Annotations: map[string]string{},
Version: "",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("generate called")
err := Copy(args[1], args[2])
if err != nil {
fmt.Printf("Error")
return
}
fmt.Println("Created", args[0], "files")
},
SilenceErrors: false,
SilenceUsage: false,
Expand All @@ -67,5 +70,4 @@ func init() {

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// generateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
43 changes: 43 additions & 0 deletions cmd/ioutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Package cmd tmake
Copyright © 2021 Yash Pandey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"io"
"os"
)

// Copy : copying a file src to dst
func Copy(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()

out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()

_, err = io.Copy(out, in)
if err != nil {
return err
}
return out.Close()
}

0 comments on commit 23a8d23

Please sign in to comment.