Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Improve project management

proji:
- Add sub command 'set': Reset info about a project
- Add sub command 'ls': List projects
- Add sub command 'rm': Remove one or more projects
- Add sub command 'clean': Clean the project list
- Add sub command 'add': Add an existing project to DB

New base command 'status':
- Add sub command 'add': Add one or more statuses
- Add sub command 'rm': Remove one or more statuses
- Add sub command 'ls': List statuses

Storage:
- Add new functions to manage items

Bugs:
- Close a bug where the notification of 'class export' would print an
empty file name
  • Loading branch information
nikoksr committed Sep 26, 2019
2 parents de45553 + 7123aa9 commit 009e248
Show file tree
Hide file tree
Showing 29 changed files with 1,165 additions and 150 deletions.
2 changes: 1 addition & 1 deletion cmd/proji/cmd/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var classCmd = &cobra.Command{
Use: "class",
Short: "work on proji classes",
Short: "Manage classes",
}

func init() {
Expand Down
8 changes: 4 additions & 4 deletions cmd/proji/cmd/classAdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
)

var classAddCmd = &cobra.Command{
Use: "add CLASS [CLASS...]",
Short: "add new classes",
Use: "add NAME [NAME...]",
Short: "Add one or more classes",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("missing class name")
return fmt.Errorf("Missing class name")
}

for _, name := range args {
Expand Down Expand Up @@ -80,7 +80,7 @@ func getLabels(reader *bufio.Reader, class *storage.Class) error {

class.Labels = strings.Fields(text)
if len(class.Labels) < 1 {
return fmt.Errorf("you have to specify atleast one label")
return fmt.Errorf("You have to specify atleast one label")
}

fmt.Println()
Expand Down
12 changes: 6 additions & 6 deletions cmd/proji/cmd/classExport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import (
var exampleDest string

var classExportCmd = &cobra.Command{
Use: "export CLASS [CLASS...]",
Short: "export proji classes to config files",
Use: "export NAME [NAME...]",
Short: "Export one or more classes",
RunE: func(cmd *cobra.Command, args []string) error {
if len(exampleDest) > 0 {
return storage.ExportExample(exampleDest)
}

if len(args) < 1 {
return fmt.Errorf("missing class name")
return fmt.Errorf("Missing class name")
}
for _, name := range args {
var file string
if file, err := ExportClass(name); err != nil {
file, err := ExportClass(name)
if err != nil {
fmt.Printf("Export of class %s to file %s failed: %v\n", name, file, err)
continue
}
Expand All @@ -36,7 +36,7 @@ var classExportCmd = &cobra.Command{

func init() {
classCmd.AddCommand(classExportCmd)
classExportCmd.Flags().StringVarP(&exampleDest, "example", "e", "", "export example config")
classExportCmd.Flags().StringVarP(&exampleDest, "example", "e", "", "Export an example")
}

// ExportClass exports a class to a toml file.
Expand Down
6 changes: 3 additions & 3 deletions cmd/proji/cmd/classImport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

var classImportCmd = &cobra.Command{
Use: "import FILE [FILE...]",
Short: "import classes from config files",
Short: "Import one or more classes",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("missing configfile name")
return fmt.Errorf("Missing configfile name")
}

for _, config := range args {
Expand All @@ -35,7 +35,7 @@ func init() {
// ImportClass imports a class from a config file.
func ImportClass(config string) error {
// Import class data
c, err := storage.NewClass("")
c, err := storage.NewClass("temp")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/proji/cmd/classLs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// lsCmd represents the ls command
var classLsCmd = &cobra.Command{
Use: "ls",
Short: "list existing classes",
Short: "List classes",
RunE: func(cmd *cobra.Command, args []string) error {
return ListClasses()
},
Expand Down Expand Up @@ -43,7 +43,7 @@ func ListClasses() error {
// Table header
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Name", "Labels"})
t.AppendHeader(table.Row{"ID", "Name", "Labels"})

// Fill table
for _, class := range classes {
Expand Down
6 changes: 3 additions & 3 deletions cmd/proji/cmd/classRm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

var classRmCmd = &cobra.Command{
Use: "rm CLASS [CLASS...]",
Short: "remove existing classes",
Use: "rm NAME [NAME...]",
Short: "Remove one or more classes",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("missing class name")
return fmt.Errorf("Missing class name")
}

for _, name := range args {
Expand Down
6 changes: 3 additions & 3 deletions cmd/proji/cmd/classShow.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
)

var classShowCmd = &cobra.Command{
Use: "show CLASS [CLASS...]",
Short: "show detailed class informations",
Use: "show NAME [NAME...]",
Short: "Show details about one or more classes",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("missing class name")
return fmt.Errorf("Missing class name")
}

for _, name := range args {
Expand Down
2 changes: 1 addition & 1 deletion cmd/proji/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var completionCmd = &cobra.Command{
Use: "completion SHELL",
Short: "add shell completion",
Short: "Add shell completion",
Hidden: true,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/proji/cmd/completionBash.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var completionBashCmd = &cobra.Command{
Use: "bash",
Short: "bash completion",
Short: "Bash completion",
RunE: func(cmd *cobra.Command, args []string) error {
return rootCmd.GenBashCompletionFile("proji-bash-completion")
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/proji/cmd/completionZsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var completionZshCmd = &cobra.Command{
Use: "zsh",
Short: "zsh completion",
Short: "Zsh completion",
RunE: func(cmd *cobra.Command, args []string) error {
return rootCmd.GenZshCompletionFile("proji-zsh-completion")
},
Expand Down
73 changes: 0 additions & 73 deletions cmd/proji/cmd/create.go

This file was deleted.

71 changes: 71 additions & 0 deletions cmd/proji/cmd/projectAdd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cmd

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/nikoksr/proji/pkg/helper"
"github.com/nikoksr/proji/pkg/proji/storage"
"github.com/nikoksr/proji/pkg/proji/storage/sqlite"
"github.com/spf13/cobra"
)

var addCmd = &cobra.Command{
Use: "add LABEL PATH",
Short: "Add an existing project",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return fmt.Errorf("Missing label or path")
}

path, err := filepath.Abs(args[1])
if !helper.DoesPathExist(path) {
return fmt.Errorf("path '%s' does not exist", path)
}

name := filepath.Base(path)
if err != nil {
return err
}
cwd, err := os.Getwd()
if err != nil {
return err
}
label := strings.ToLower(args[0])

if err := AddProject(name, label, cwd); err != nil {
return err
}
fmt.Printf("Project '%s' was successfully added.\n", path)
return nil
},
}

func init() {
rootCmd.AddCommand(addCmd)
}

// AddProject will create a new project or return an error if the project already exists.
func AddProject(name, label, cwd string) error {
// Setup storage
sqlitePath, err := helper.GetSqlitePath()
if err != nil {
return err
}
s, err := sqlite.New(sqlitePath)
if err != nil {
return err
}
defer s.Close()

proj, err := storage.NewProject(name, label, cwd, s)
if err != nil {
return err
}
if err := s.TrackProject(proj); err != nil {
return err
}
return nil
}
Loading

0 comments on commit 009e248

Please sign in to comment.