-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
29 changed files
with
1,165 additions
and
150 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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,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 | ||
} |
Oops, something went wrong.