Skip to content

Commit

Permalink
Create subcommands and flags package, Add flags for help, and Add sub…
Browse files Browse the repository at this point in the history
…command for Add, Remove and Init
  • Loading branch information
SwayKh committed Sep 10, 2024
1 parent 75cac91 commit 015809b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions cmd/flags.go
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)
}

0 comments on commit 015809b

Please sign in to comment.