dnote/cmd/root/root.go
Sung Won Cho d31b22aed0
Improve output and edit command (#52)
* Refine output

* Show note content while editing

* v0.2.0-alpha.2
2018-01-07 18:18:47 +11:00

77 lines
1.7 KiB
Go

package root
import (
"github.com/dnote-io/cli/core"
"github.com/dnote-io/cli/infra"
"github.com/dnote-io/cli/migrate"
"github.com/dnote-io/cli/upgrade"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var root = &cobra.Command{
Use: "dnote",
Short: "Dnote - Instantly capture what you learn while coding",
SilenceErrors: true,
SilenceUsage: true,
}
// Register adds a new command
func Register(cmd *cobra.Command) {
root.AddCommand(cmd)
}
// Execute runs the main command
func Execute() error {
return root.Execute()
}
// Prepare initializes necessary files
func Prepare(ctx infra.DnoteCtx) error {
err := core.MigrateToDnoteDir(ctx)
if err != nil {
return errors.Wrap(err, "Failed to initialize dnote dir")
}
fresh, err := core.IsFreshInstall(ctx)
if err != nil {
return errors.Wrap(err, "Failed to check if fresh install")
}
err = core.InitDnoteDir(ctx)
if err != nil {
return errors.Wrap(err, "Failed to create dnote dir")
}
err = core.InitConfigFile(ctx)
if err != nil {
return errors.Wrap(err, "Failed to generate config file")
}
err = core.InitDnoteFile(ctx)
if err != nil {
return errors.Wrap(err, "Failed to create dnote file")
}
err = core.InitTimestampFile(ctx)
if err != nil {
return errors.Wrap(err, "Failed to create dnote upgrade file")
}
err = core.InitActionFile(ctx)
if err != nil {
return errors.Wrap(err, "Failed to create action file")
}
err = migrate.InitSchemaFile(ctx, fresh)
if err != nil {
return errors.Wrap(err, "Failed to create migration file")
}
err = migrate.Migrate(ctx)
if err != nil {
return errors.Wrap(err, "Failed to perform migration")
}
err = upgrade.AutoUpgrade(ctx)
if err != nil {
return errors.Wrap(err, "Failed to auto upgrade")
}
return nil
}