commands

package
v5.1.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Add = &cobra.Command{
	Use:   "add",
	Short: "Add a file to the current profile.",
	Run: func(cmd *cobra.Command, args []string) {
		if verbose {
			fmt.Println("Adding files:", args)
		}

		profile := config.CurrentProfile()

		for _, f := range args {
			addFileToProfile(f, profile)
		}

		err := git.Sync(profile)
		if err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}
	},
}

Add will add the specified profile to the current profile, linking it as necessary.

View Source
var Clean = &cobra.Command{
	Use:   "clean",
	Short: "clean dead symlinks",
	Long:  "Clean looks for any symlinks which are broken and cleans them up. This can happen if files are removed from the profile directory manually instead of through dfm.",
	Run: func(cmd *cobra.Command, args []string) {
		homeDir := os.Getenv("HOME")
		if err := cleanDeadLinks(homeDir); err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}

		xdg := os.Getenv("XDG_CONFIG_HOME")
		if xdg == "" {
			xdg = filepath.Join(os.Getenv("HOME"), ".config")
		}

		if err := cleanDeadLinks(xdg); err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}
	},
}

Clean looks for any symlinks which are broken and cleans them up. This can happen if files are removed from the profile directory manually instead of through dfm.

View Source
var Clone = &cobra.Command{
	Use:   "clone",
	Short: "git clone an existing profile from `URL`",
	Run: func(cmd *cobra.Command, args []string) {
		url, user := CreateURL(strings.Split(args[0], "/"))
		userDir := filepath.Join(config.ProfileDir(), user)
		if name != "" {
			userDir = filepath.Join(config.ProfileDir(), name)
		}

		if err := CloneRepo(url, userDir); err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}

		yml := config.LoadDotDFM(userDir)
		for _, module := range yml.Modules {

			module.Location()
		}

		if link {
			args := []string{"dfm", "link", user}
			if overwrite {
				args = []string{"dfm", "link", "-o", user}
			}

			c := exec.Command(args[0], args[1:]...)
			_, err := c.CombinedOutput()
			if err != nil {
				fmt.Println("ERROR:", err.Error())
				os.Exit(1)
			}
		}
	},
}

Clone will clone the given git repo to the profiles directory, it optionally will call link or use depending on the flag given.

View Source
var Git = &cobra.Command{
	Use:                "git",
	Args:               cobra.ArbitraryArgs,
	Short:              "run the given git command on the current profile",
	DisableFlagParsing: true,
	Run: func(cmd *cobra.Command, args []string) {
		profile := config.CurrentProfile()

		if err := git.RunGitCMD(profile, args...); err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}
	},
}

Git runs arbitrary git commands on the current profile

View Source
var Init = &cobra.Command{
	Use:   "init",
	Short: "create a new profile with `NAME`",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			fmt.Println("Please specify a profile name.")
			os.Exit(1)
		}

		profileDir := config.ProfileDir()
		profile := filepath.Join(profileDir, args[0])
		err := os.MkdirAll(profile, os.ModePerm)
		if err != nil {
			fmt.Println("ERROR: Unable create profile directory: ", profile, err)
			os.Exit(1)
		}

		err = git.Init(profile)
		if err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}
	},
}

Init will create a new profile with the given name.

View Source
var Link = &cobra.Command{
	Use:   "link",
	Short: "link the profile with `NAME`",
	Long:  "will generate and create the symlinks to the dotfiles in the profile",
	Run: func(cmd *cobra.Command, args []string) {
		profile := config.CurrentProfile()
		if len(args) >= 1 {
			profile = config.GetProfileByName(args[0])
		}

		fmt.Println("Linking profile", profile)

		linkProfile(profile)
	},
}

Link will generate and create the symlinks to the dotfiles in the repo.

View Source
var List = &cobra.Command{
	Use:   "list",
	Short: "list available profiles",
	Run: func(cmd *cobra.Command, args []string) {
		profiles := config.AvailableProfiles()
		for _, profile := range profiles {
			fmt.Println(profile)
		}
	},
}

List will list the available profiles and aliases

View Source
var Remove = &cobra.Command{
	Use:   "remove",
	Short: "remove the profile with `NAME`",
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		profile := args[0]
		userDir := filepath.Join(config.ProfileDir(), profile)

		dfmyml := config.LoadDotDFM(userDir)
		mappings := append(dfmyml.Mappings, filemap.DefaultMappings()...)

		links, err := linking.GenerateSymlinks(userDir, os.Getenv("HOME"), mappings)
		if err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}

		rmerr := os.RemoveAll(userDir)
		if rmerr != nil {
			fmt.Println("ERROR:", rmerr.Error())
			os.Exit(1)
		}

		if verbose {
			fmt.Println("Removed profile directory:", userDir)
		}

		if err := RemoveSymlinks(links, args[0]); err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}
	},
}

Remove will remove the specified profile

View Source
var Root = &cobra.Command{
	Use:   "dfm",
	Short: "Manage dotfiles.",
	Long: `Dotfile management written for pair programmers. Examples on getting
started with dfm are avialable at https://github.com/chasinglogic/dfm`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		config.Init()
	},
}

Root is the root dfm command.

View Source
var RunHook = &cobra.Command{
	Use:   "run-hook",
	Short: "Run the hook specified by `HOOK`",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			fmt.Println("ERROR: Must specify at least one hook to run")
			os.Exit(128)
		}

		profile := config.CurrentProfile()
		yml := config.LoadDotDFM(profile)
		config.RunCommands(yml.Hooks[args[0]])
	},
}

RunHook will add the specified profile to the current profile, linking it as necessary.

View Source
var Sync = &cobra.Command{
	Use:   "sync",
	Short: "sync the current profile with the configured backend",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		profile := config.CurrentProfile()
		if err := git.Sync(profile); err != nil {
			fmt.Println("ERROR:", err.Error())
			os.Exit(1)
		}

		yml := config.LoadDotDFM(profile)
		if !(yml.SyncModules || syncModules) {
			return
		}

		for _, module := range yml.Modules {
			location := module.Location()
			if module.PullOnly {
				err := git.Pull(location)
				if err != nil {
					fmt.Println("ERROR: Unable to update module:", err)
				}
			} else {
				err := git.Sync(location)
				if err != nil {
					fmt.Println("ERROR: Unable to sync module:", err)
				}
			}
		}
	},
}

Sync will sync the current profile with the configured backend

View Source
var Where = &cobra.Command{
	Use:   "where",
	Short: "prints the first location for the current profile directory path",
	Run: func(cmd *cobra.Command, args []string) {
		profile := config.CurrentProfile()
		fmt.Println(profile)
	},
}

Where simply prints the current profile directory path

Functions

func CloneRepo

func CloneRepo(url, profileDir string) error

CloneRepo will git clone the provided url into the appropriate profileDir

func CreateURL

func CreateURL(s []string) (string, string)

CreateURL will add the missing github.com for the shorthand version of links.

func Execute

func Execute() error

Execute aliases to running Execute on the root command

func RemoveSymlinks(l []linking.LinkInfo, username string) error

RemoveSymlinks will remove all of the symlinks after removing a profile it will first Check if the link is still valid after removing the profile, and if so just verify that it doesn't contain the username of the profile we're deleting. If the profile we're removing is the one that was currently in use then both conditions should be true.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL