-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
163 changed files
with
15,088 additions
and
21 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
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
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,12 @@ | ||
Use build flag to selectively activate v2 functionality? | ||
Add dir to RunScript? | ||
Encryption should use System.IdempotentCommandOutput | ||
Encryption | ||
Test EncryptionTool that uses randomly generated key | ||
|
||
script name is currently part of run once state (in key) | ||
need to decide whether rename of script means its a different script | ||
also executedAt in JSON representation should probably be runAt | ||
|
||
document dump --recursive | ||
document global --output |
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
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
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
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,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/twpayne/chezmoi/next/internal/chezmoi" | ||
) | ||
|
||
var addCmd = &cobra.Command{ | ||
Use: "add targets...", | ||
Aliases: []string{"manage"}, | ||
Args: cobra.MinimumNArgs(1), | ||
Short: "Add an existing file, directory, or symlink to the source state", | ||
Long: mustGetLongHelp("add"), | ||
Example: getExample("add"), | ||
RunE: config.runAddCmd, // FIXME | ||
Annotations: map[string]string{ | ||
modifiesSourceDirectory: "true", | ||
}, | ||
} | ||
|
||
type addCmdConfig struct { | ||
autoTemplate bool | ||
empty bool | ||
encrypt bool | ||
exact bool | ||
include *chezmoi.IncludeBits | ||
recursive bool | ||
template bool | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(addCmd) | ||
|
||
persistentFlags := addCmd.PersistentFlags() | ||
persistentFlags.BoolVarP(&config.add.autoTemplate, "autotemplate", "a", config.add.autoTemplate, "auto generate the template when adding files as templates") | ||
persistentFlags.BoolVarP(&config.add.empty, "empty", "e", config.add.empty, "add empty files") | ||
persistentFlags.BoolVar(&config.add.encrypt, "encrypt", config.add.encrypt, "encrypt files") | ||
persistentFlags.BoolVarP(&config.add.exact, "exact", "x", config.add.exact, "add directories exactly") | ||
persistentFlags.BoolVarP(&config.add.recursive, "recursive", "r", config.add.recursive, "recursive") | ||
persistentFlags.BoolVarP(&config.add.template, "template", "T", config.add.template, "add files as templates") | ||
} | ||
|
||
func (c *Config) runAddCmd(cmd *cobra.Command, args []string) error { | ||
destPathInfos, err := c.getDestPathInfos(args, c.add.recursive) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s, err := c.getSourceState() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return s.Add(c.system, c.DestDir, destPathInfos, &chezmoi.AddOptions{ | ||
AutoTemplate: c.add.autoTemplate, | ||
Empty: c.add.empty, | ||
Encrypt: c.add.encrypt, | ||
Exact: c.add.exact, | ||
Include: c.add.include, | ||
Template: c.add.template, | ||
}) | ||
} |
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,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/twpayne/chezmoi/next/internal/chezmoi" | ||
) | ||
|
||
var applyCmd = &cobra.Command{ | ||
Use: "apply [targets...]", | ||
Short: "Update the destination directory to match the target state", | ||
Long: mustGetLongHelp("apply"), | ||
Example: getExample("apply"), | ||
RunE: config.runApplyCmd, | ||
Annotations: map[string]string{ | ||
modifiesDestinationDirectory: "true", | ||
}, | ||
} | ||
|
||
type applyCmdConfig struct { | ||
include *chezmoi.IncludeBits | ||
recursive bool | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(applyCmd) | ||
|
||
persistentFlags := applyCmd.PersistentFlags() | ||
persistentFlags.VarP(config.apply.include, "include", "i", "include entry types") | ||
persistentFlags.BoolVarP(&config.apply.recursive, "recursive", "r", config.apply.recursive, "recursive") | ||
|
||
markRemainingZshCompPositionalArgumentsAsFiles(applyCmd, 1) | ||
} | ||
|
||
func (c *Config) runApplyCmd(cmd *cobra.Command, args []string) error { | ||
return c.applyArgs(c.system, c.DestDir, args, c.apply.include, c.apply.recursive) | ||
} |
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,81 @@ | ||
package cmd | ||
|
||
// FIXME add -j option to bzip2 compress output | ||
// FIXME add -z option to gzip compress output | ||
|
||
import ( | ||
"archive/tar" | ||
"os/user" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/twpayne/chezmoi/next/internal/chezmoi" | ||
) | ||
|
||
var archiveCmd = &cobra.Command{ | ||
Use: "archive [targets...]", | ||
Short: "Generate a tar archive of the target state", | ||
Long: mustGetLongHelp("archive"), | ||
Example: getExample("archive"), | ||
RunE: config.runArchiveCmd, | ||
} | ||
|
||
type archiveCmdConfig struct { | ||
include *chezmoi.IncludeBits | ||
recursive bool | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(archiveCmd) | ||
|
||
persistentFlags := archiveCmd.PersistentFlags() | ||
persistentFlags.VarP(config.archive.include, "include", "i", "include entry types") | ||
persistentFlags.BoolVarP(&config.archive.recursive, "recursive", "r", config.archive.recursive, "recursive") | ||
} | ||
|
||
func (c *Config) runArchiveCmd(cmd *cobra.Command, args []string) error { | ||
sb := &strings.Builder{} | ||
tarSystem := chezmoi.NewTARSystem(sb, tarHeaderTemplate()) | ||
if err := c.applyArgs(tarSystem, "", args, c.archive.include, c.archive.recursive); err != nil { | ||
return err | ||
} | ||
if err := tarSystem.Close(); err != nil { | ||
return err | ||
} | ||
return c.writeOutputString(sb.String()) | ||
} | ||
|
||
// tarHeaderTemplate returns a tar.Header template populated with the current | ||
// user and time. | ||
func tarHeaderTemplate() tar.Header { | ||
// Attempt to lookup the current user. Ignore errors because the default | ||
// zero values are reasonable. | ||
var ( | ||
uid int | ||
gid int | ||
Uname string | ||
Gname string | ||
) | ||
if currentUser, err := user.Current(); err == nil { | ||
uid, _ = strconv.Atoi(currentUser.Uid) | ||
gid, _ = strconv.Atoi(currentUser.Gid) | ||
Uname = currentUser.Username | ||
if group, err := user.LookupGroupId(currentUser.Gid); err == nil { | ||
Gname = group.Name | ||
} | ||
} | ||
|
||
now := time.Now() | ||
return tar.Header{ | ||
Uid: uid, | ||
Gid: gid, | ||
Uname: Uname, | ||
Gname: Gname, | ||
ModTime: now, | ||
AccessTime: now, | ||
ChangeTime: now, | ||
} | ||
} |
Oops, something went wrong.