-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: separating cmd documentation from use cases documentation
- Loading branch information
1 parent
4e0d0cf
commit f99c3cb
Showing
5 changed files
with
125 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package commit | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/go-git/go-git/v5" | ||
) | ||
|
||
func AskCommitPrefix() string { | ||
var prefix string | ||
err := survey.AskOne( | ||
&survey.Select{ | ||
Message: "Select a Prefix for the commit:", | ||
Options: []string{"chore", "feat", "fix", "refactor", "tests", "docs", "build"}, | ||
}, | ||
&prefix, | ||
) | ||
|
||
if err != nil { | ||
log.Fatal("Could not ask Commit Prefix") | ||
} | ||
|
||
return prefix | ||
} | ||
|
||
func ResolveCommitMessage() string { | ||
var message string | ||
err := survey.AskOne( | ||
&survey.Input{ | ||
Message: "What did you do? (Commit Message):", | ||
}, | ||
&message, | ||
) | ||
|
||
if err != nil { | ||
log.Fatal("Could not ask Commit Message") | ||
} | ||
|
||
return message | ||
} | ||
|
||
func ConventionalCommit(prefix string, message string, worktree *git.Worktree) { | ||
formatedMessage := fmt.Sprintf("%s: %s", prefix, message) | ||
worktree.Commit(formatedMessage, &git.CommitOptions{}) | ||
fmt.Println("Sucessfully added a commit!") | ||
} |
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,21 @@ | ||
package repo | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/go-git/go-git/v5" | ||
) | ||
|
||
func GetRepository(pathToRepository string) *git.Worktree { | ||
repository, err := git.PlainOpen(pathToRepository) | ||
if err != nil { | ||
log.Fatal("Could not open Git Repo") | ||
} | ||
|
||
worktree, err := repository.Worktree() | ||
if err != nil { | ||
log.Fatal("Could not get Work Tree") | ||
} | ||
|
||
return worktree | ||
} |
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,46 @@ | ||
package staging | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/go-git/go-git/v5" | ||
) | ||
|
||
func GetUnstaggedFiles(worktree *git.Worktree) []string { | ||
status, err := worktree.Status() | ||
if err != nil { | ||
log.Fatal("Could not get Git Status") | ||
} | ||
|
||
var modifiedOrUntrackedFiles []string | ||
for file, s := range status { | ||
if s.Worktree == git.Modified || s.Worktree == git.Untracked { | ||
modifiedOrUntrackedFiles = append(modifiedOrUntrackedFiles, file) | ||
} | ||
} | ||
|
||
return modifiedOrUntrackedFiles | ||
} | ||
|
||
func AskWhatFilesToAddForStaging(files []string) []string { | ||
var filesToAdd []string | ||
prompt := &survey.MultiSelect{ | ||
Message: "Chose the files to stage:", | ||
Options: files, | ||
} | ||
err := survey.AskOne(prompt, &filesToAdd) | ||
if err != nil { | ||
log.Fatal("Could not Ask Files to Stage") | ||
} | ||
return filesToAdd | ||
} | ||
|
||
func StageFiles(files []string, worktree *git.Worktree) { | ||
for _, file := range files { | ||
_, err := worktree.Add(file) | ||
if err != nil { | ||
log.Fatal("Could not add " + file + " file") | ||
} | ||
} | ||
} |