Skip to content

Commit

Permalink
docs: separating cmd documentation from use cases documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
KaueSabinoSRV17 committed Jun 22, 2023
1 parent 84ea6df commit 4e0d0cf
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,46 @@ Where we store `Go` files generated by `Cobra`. They add the functionality of a
##### Commit Command

The `Commit Command`can be called without any arguments, and that is actually the main Use Case.
It is configured in the `commit.go` file, inside the `cmd` directory. It will:
It is configured in the `commit.go` file, inside the `cmd` directory. The function inside the `Run`
Attribute of the `Cobra Command` is the following:

```go
func(cmd *cobra.Command, args []string) {
repo := use_cases.GetRepository(".")
var message string
unstagedFiles := use_cases.GetUnstaggedFiles(repo)
if len(unstagedFiles) > 0 {
filesToStage := use_cases.AskWhatFilesToAddForStaging(unstagedFiles)
go use_cases.StageFiles(filesToStage, repo)
}
prefix := use_cases.AskCommitPrefix()
if len(args) == 0 {
message = use_cases.ResolveCommitMessage()
} else {
message = args[0]
}
use_cases.ConventionalCommit(prefix, message, repo)
}
```

#### infra

Where we store `terraform` files that describe and mainteen any infrastructure that we need to publish the CLI.
Currently there is only a `S3 Bucket` in `AWS`, that we are trying to use as a repository for `apt`, making it
easier to install on Linux.

#### use_cases directory

Where we store business logic to implement the `Use Cases` of the CLI (Currently only Conventional Commits).

##### Conventional Commit

The logic for the commit message is inside the `conventional_commit.go` file, in the `use_cases` directory.
The following is the implementation of the Use Case:

- Open the Git Repo via `go-git` package:
```go
Expand Down Expand Up @@ -197,39 +236,4 @@ func ConventionalCommit(prefix string, message string, worktree *git.Worktree) {
worktree.Commit(formatedMessage, &git.CommitOptions{})
fmt.Println("Sucessfully added a commit!")
}
```

The full function inside the `Run` Attribute of the `Cobra Command` is like this:

```go
func(cmd *cobra.Command, args []string) {
repo := use_cases.GetRepository(".")
var message string
unstagedFiles := use_cases.GetUnstaggedFiles(repo)
if len(unstagedFiles) > 0 {
filesToStage := use_cases.AskWhatFilesToAddForStaging(unstagedFiles)
go use_cases.StageFiles(filesToStage, repo)
}
prefix := use_cases.AskCommitPrefix()
if len(args) == 0 {
message = use_cases.ResolveCommitMessage()
} else {
message = args[0]
}
use_cases.ConventionalCommit(prefix, message, repo)
}
```

#### infra

Where we store `terraform` files that describe and mainteen any infrastructure that we need to publish the CLI.
Currently there is only a `S3 Bucket` in `AWS`, that we are trying to use as a repository for `apt`, making it
easier to install on Linux.

#### use_cases directory

Where we store business logic to implement the `Use Cases` of the CLI (Currently only Conventional Commits).
```

0 comments on commit 4e0d0cf

Please sign in to comment.