Skip to content

Commit

Permalink
[feature] Add commit with init key
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamontat Chantrachirathumrong committed Sep 11, 2018
1 parent 5ea9a9d commit 465780a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
7 changes: 3 additions & 4 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var commitCmd = &cobra.Command{
Use: "commit",
Aliases: []string{"c"},
Short: "Git commit with format string",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
om.Log.ToLog("commit", "start...")

Expand Down Expand Up @@ -68,7 +67,7 @@ var all bool
func init() {
rootCmd.AddCommand(commitCmd)

commitCmd.PersistentFlags().StringArrayVarP(&each, "each", "e", []string{}, "Commit with add [multiple use]")
commitCmd.PersistentFlags().BoolVarP(&all, "all", "A", false, "Commit with add all")
commitCmd.PersistentFlags().BoolVarP(&add, "add", "a", false, "Commit with -a flag")
commitCmd.Flags().StringArrayVarP(&each, "each", "e", []string{}, "Commit with add [multiple use]")
commitCmd.Flags().BoolVarP(&all, "all", "A", false, "Commit with add all")
commitCmd.Flags().BoolVarP(&add, "add", "a", false, "Commit with -a flag")
}
85 changes: 85 additions & 0 deletions cmd/commitInitial.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright © 2018 Kamontat Chantrachirathumrong <kamontat.c@hotmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"os"

"github.com/kamontat/gitgo/model"

"github.com/kamontat/go-log-manager"
"github.com/spf13/cobra"
)

// commitInitialCmd represents the commitInitial command
var commitInitialCmd = &cobra.Command{
Use: "initial",
Aliases: []string{"i", "init", "start", "s"},
Short: "Start commit and add every file if not add",
Run: func(cmd *cobra.Command, args []string) {
om.Log.ToVerbose("Commit initial", "start...")
repo.AddAll().ShowMessage().Exit()
om.Log.ToVerbose("Status", "Added all files or folders")

om.Log.ToVerbose("Status", "Getting commit object")
commit := repo.GetCommit()

if commit.CanCommit() {
om.Log.ToVerbose("Commit", "Start create commit")

if key == "" {
key = "init"
}

if title == "" {
title = "Initial commit with files"
}

message := `We create this commit for initial repostiory.
Commit 'gitgo' project [https://github.com/kamontat/gitgo].`

if !hasMessage {
message = ""
}

commit.CustomCommit(true, model.CommitMessage{
Key: key,
Title: title,
Message: message,
})
} else {
om.Log.ToError("Repository", "Cannot create commit")
os.Exit(1)
}
},
}

var key string
var title string
var hasMessage bool

func init() {
commitCmd.AddCommand(commitInitialCmd)

commitInitialCmd.Flags().StringVarP(&key, "key", "k", "init", "Custom commit key [default=init]")
commitInitialCmd.Flags().StringVarP(&title, "title", "t", "Initial commit with files", "Custom commit title [default=Initial commit with files]")
commitInitialCmd.Flags().BoolVarP(&hasMessage, "no-message", "N", false, "Force commit to not use message. [default=false]")
}
1 change: 0 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var configCmd = &cobra.Command{
Use: "config",
Aliases: []string{"C", "configuration"},
Short: "Gitgo configuration",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
om.Log.ToLog("config", "start...")

Expand Down
1 change: 0 additions & 1 deletion cmd/configInitial.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var configInitialCmd = &cobra.Command{
Use: "init",
Aliases: []string{"i", "initial"},
Short: "Create and initial gitgo configuration files",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
om.Log.ToLog("config", "initial start...")
yaml := model.GeneratorYAML()
Expand Down
1 change: 0 additions & 1 deletion cmd/configOpen.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var configOpenCmd = &cobra.Command{
Use: "open",
Aliases: []string{"o"},
Short: "open config in your default editor",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
om.Log.ToLog("config", "open start...")

Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var rootCmd = &cobra.Command{
Use: "gitgo",
Short: "gitgo command by Kamontat Chantrachurathumrong",
Version: "2.0.3",
Long: ``,
}

// Execute is execute method that call by cobra cli.
Expand Down

0 comments on commit 465780a

Please sign in to comment.