-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create subcommands and flags package, Add flags for help, and Add sub…
…command for Add, Remove and Init
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/SwayKh/linksym/pkg/config" | ||
) | ||
|
||
var ( | ||
AddFlag *flag.FlagSet | ||
RemoveFlag *flag.FlagSet | ||
InitFlag *flag.FlagSet | ||
HelpFlag *bool | ||
SPath string | ||
DPath string | ||
RemovePath string | ||
) | ||
|
||
func CreateFlags() { | ||
// Handle both -h and --help with one boolean | ||
HelpFlag = flag.Bool("h", false, "Show help") | ||
flag.BoolVar(HelpFlag, "help", false, "Show help") | ||
|
||
AddFlag = flag.NewFlagSet("add", flag.ExitOnError) | ||
RemoveFlag = flag.NewFlagSet("remove", flag.ExitOnError) | ||
InitFlag = flag.NewFlagSet("init", flag.ExitOnError) | ||
|
||
AddFlag.StringVar(&SPath, "source", "", "Source path for the file to symlink") | ||
AddFlag.StringVar(&DPath, "destination", "", "(Optional) Destination for symlink") | ||
|
||
RemoveFlag.StringVar(&RemovePath, "path", "", "Path to remove symlink") | ||
} | ||
|
||
func Init() error { | ||
err := config.InitialiseConfig() | ||
if err != nil { | ||
fmt.Printf("Error initialising config: %s\n", err) | ||
os.Exit(1) | ||
} | ||
return nil | ||
} | ||
|
||
func Add() error { | ||
return nil | ||
} | ||
|
||
func Remove() error { | ||
return nil | ||
} | ||
|
||
func Help() { | ||
fmt.Println("Usage: linksym [subcommand] [flags]") | ||
|
||
fmt.Println("\n Subcommands:") | ||
fmt.Println(" add [Path] [(optional) Destination]:") | ||
fmt.Println(" Create a symlink for given path, optionally define a destination for symlink") | ||
fmt.Println(" remove [Path]") | ||
fmt.Println(" Remove the symlink and move the file to the original path") | ||
|
||
fmt.Println("\n Flags:") | ||
fmt.Println(" -h, --help") | ||
fmt.Println(" Print this help message") | ||
os.Exit(1) | ||
} |