Skip to content

Commit

Permalink
add a scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
lylex committed Nov 22, 2018
1 parent 96412ba commit cf3ecf3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/ls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

const (
lsCmdUse = "ls"
)

// lsCmd represents the ls command.
// TODO fill the TBDs
var lsCmd = &cobra.Command{
Use: lsCmdUse,
Short: "short TBD",
Long: `long TBD`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("in the ls cmd")
},
}

func init() {
RootCmd.AddCommand(lsCmd)
}
53 changes: 53 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

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

"github.com/spf13/cobra"
)

const (
// RootCmdName represents the cobra root command name.
RootCmdName = "drm"

// TODO replate it
TempFileStorePath = "/home/lylex/workspace/drm/temp"
)

var (
isForce bool
isRecursive bool
)

// RootCmd represents the base command.
var RootCmd = &cobra.Command{
Use: RootCmdName,
Short: "A delayed rm with safety.",
Long: `This application is used to rm files with a latency.`,
Run: func(cmd *cobra.Command, args []string) {
dir, _ := os.Getwd()
for _, item := range args {
// err := os.Rename(originalPath, newPath)
currentPath := filepath.Join(dir, item)
fmt.Println(currentPath)
}
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute command: %+v\n", err)
os.Exit(1)
}
}

func init() {
RootCmd.Flags().BoolVarP(&isRecursive, "recursive", "r", false, `ignore
nonexistent files and arguments, never prompt`)
RootCmd.Flags().BoolVarP(&isForce, "force", "f", false, `remove directories
and their contents recursively or not`)
}
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/lylex/drm

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/lylex/drm/cmd"

func main() {
cmd.Execute()
}

0 comments on commit cf3ecf3

Please sign in to comment.