Skip to content

Commit b1ee661

Browse files
committed
Revert "Remove code"
This reverts commit 91e19f7.
1 parent 91e19f7 commit b1ee661

24 files changed

Lines changed: 1970 additions & 0 deletions

.github/workflows/build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build Main Branch
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.24.1'
20+
21+
- name: Build the project
22+
run: go build -o build/dloom
23+
24+
- name: Verify build output
25+
run: ls -l build/dloom

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
- 'v*.*.*.rc.*'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: '1.24.1'
24+
25+
- name: Set VERSION from tag
26+
id: get_version
27+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
28+
29+
- name: Build the project
30+
run: |
31+
go build -ldflags "-X github.com/dloomorg/dloom/cmd.Version=${{ env.VERSION }}" -o build/dloom
32+
33+
- name: Check if prerelease
34+
id: prerelease
35+
run: |
36+
if [[ "${GITHUB_REF##*/}" == *".rc."* ]]; then
37+
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
38+
else
39+
echo "IS_PRERELEASE=false" >> $GITHUB_ENV
40+
fi
41+
42+
- name: Create GitHub Release
43+
uses: softprops/action-gh-release@v1
44+
with:
45+
files: build/dloom
46+
prerelease: ${{ env.IS_PRERELEASE }}
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: build clean test run
2+
3+
BINARY_NAME=dloom
4+
BUILD_DIR=bin
5+
6+
build:
7+
@echo "Building $(BINARY_NAME) in $(BUILD_DIR)..."
8+
@mkdir -p $(BUILD_DIR)
9+
@echo "Created build dir $(BUILD_DIR)..."
10+
@echo "Invoking go build -o $(BUILD_DIR)/$(BINARY_NAME)..."
11+
@go build -o $(BUILD_DIR)/$(BINARY_NAME)
12+
@echo "Completed go build to $(BUILD_DIR)/$(BINARY_NAME)..."
13+
@echo "Directory listing for $(BUILD_DIR)..."
14+
@ls -la $(BUILD_DIR)
15+
@echo "Checking if $(BUILD_DIR)/$(BINARY_NAME) exists..."
16+
@ls -la $(BUILD_DIR)/$(BINARY_NAME)
17+
@echo "Binary $(BUILD_DIR)/$(BINARY_NAME) exists..."
18+
@echo "Making $(BUILD_DIR)/$(BINARY_NAME) executable..."
19+
@chmod +x $(BUILD_DIR)/$(BINARY_NAME)
20+
@echo "Marked $(BUILD_DIR)/$(BINARY_NAME) executable..."
21+
@echo "Completed build of $(BINARY_NAME) in $(BUILD_DIR)..."
22+
23+
clean:
24+
@echo "Cleaning $(BUILD_DIR)..."
25+
@rm -rf $(BUILD_DIR)
26+
@echo "Cleaned $(BUILD_DIR)..."
27+
28+
test:
29+
@echo "Running tests..."
30+
@go test -v ./...
31+
@echo "Completed running tests..."
32+
33+
run: build
34+
@echo "Running $(BINARY_NAME)..."
35+
@./$(BUILD_DIR)/$(BINARY_NAME)

cmd/link.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"github.com/dloomorg/dloom/internal"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var linkCmd = &cobra.Command{
10+
Use: "link [packages...]",
11+
Short: "Create symlinks for specified packages",
12+
RunE: func(cmd *cobra.Command, args []string) error {
13+
if len(args) == 0 {
14+
return errors.New("no packages specified for link command")
15+
}
16+
17+
opts := internal.LinkOptions{
18+
Config: cfg,
19+
Packages: args,
20+
}
21+
22+
return internal.LinkPackages(opts, logger)
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(linkCmd)
28+
}

cmd/root.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/dloomorg/dloom/internal"
6+
"github.com/dloomorg/dloom/internal/logging"
7+
"github.com/spf13/cobra"
8+
"os"
9+
"path/filepath"
10+
)
11+
12+
var Version string
13+
14+
var (
15+
cfg *internal.Config
16+
logger *logging.Logger
17+
18+
// flags
19+
configPath string
20+
force bool
21+
verbose bool
22+
dryRun bool
23+
sourceDir string
24+
targetDir string
25+
noColor bool
26+
)
27+
28+
var rootCmd = &cobra.Command{
29+
Use: "dloom",
30+
Short: "Dotfile manager and system bootstrapper",
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
if v, _ := cmd.Flags().GetBool("version"); v {
33+
fmt.Println("dloom version:", ifEmpty(Version, "dev"))
34+
return nil
35+
}
36+
// If no version flag, show help
37+
return cmd.Help()
38+
},
39+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
40+
logger = &logging.Logger{UseColors: !noColor}
41+
42+
var err error
43+
cfg, err = internal.LoadConfig(configPath, logger)
44+
if err != nil {
45+
return fmt.Errorf("error loading config: %w", err)
46+
}
47+
48+
if force {
49+
cfg.Force = true
50+
}
51+
if verbose {
52+
cfg.Verbose = true
53+
}
54+
if dryRun {
55+
cfg.DryRun = true
56+
}
57+
if sourceDir != "" {
58+
cfg.SourceDir = sourceDir
59+
}
60+
if targetDir != "" {
61+
cfg.TargetDir = targetDir
62+
}
63+
64+
// Absolute source dir
65+
if !filepath.IsAbs(cfg.SourceDir) {
66+
if abs, err := filepath.Abs(cfg.SourceDir); err == nil {
67+
cfg.SourceDir = abs
68+
}
69+
}
70+
71+
return nil
72+
},
73+
}
74+
75+
func ifEmpty(s, fallback string) string {
76+
if s == "" {
77+
return fallback
78+
}
79+
return s
80+
}
81+
82+
// Execute runs the root command
83+
func Execute() {
84+
if err := rootCmd.Execute(); err != nil {
85+
os.Exit(1)
86+
}
87+
}
88+
89+
func init() {
90+
rootCmd.PersistentFlags().BoolP("version", "V", false, "Print the version of dloom and exit")
91+
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "Path to config file")
92+
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "Disable color output")
93+
rootCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "Force overwrite existing files")
94+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output")
95+
rootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "Dry run (show actions without executing)")
96+
rootCmd.PersistentFlags().StringVarP(&sourceDir, "source", "s", "", "Source directory")
97+
rootCmd.PersistentFlags().StringVarP(&targetDir, "target", "t", "", "Target directory")
98+
}

cmd/setup.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"github.com/dloomorg/dloom/internal"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var setupCmd = &cobra.Command{
10+
Use: "setup [scripts...]",
11+
Short: "Run specified setup scripts",
12+
RunE: func(cmd *cobra.Command, args []string) error {
13+
if len(args) == 0 {
14+
return errors.New("no scripts specified for setup command")
15+
}
16+
17+
opts := internal.SetupOptions{
18+
Config: cfg,
19+
Scripts: args,
20+
}
21+
22+
return internal.RunScripts(opts, logger)
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(setupCmd)
28+
}

cmd/unlink.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"github.com/dloomorg/dloom/internal"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var unlinkCmd = &cobra.Command{
10+
Use: "unlink [packages...]",
11+
Short: "Remove symlinks for specified packages",
12+
RunE: func(cmd *cobra.Command, args []string) error {
13+
if len(args) == 0 {
14+
return errors.New("no packages specified for unlink command")
15+
}
16+
17+
opts := internal.UnlinkOptions{
18+
Config: cfg,
19+
Packages: args,
20+
}
21+
22+
return internal.UnlinkPackages(opts, logger)
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(unlinkCmd)
28+
}

cmd/version.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var versionCmd = &cobra.Command{
9+
Use: "version",
10+
Short: "Print the version of dloom",
11+
Run: func(cmd *cobra.Command, args []string) {
12+
fmt.Println("dloom version: ", Version)
13+
},
14+
}
15+
16+
func init() {
17+
rootCmd.AddCommand(versionCmd)
18+
}

dloom.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/dloomorg/dloom/cmd"
4+
5+
func main() {
6+
cmd.Execute()
7+
}

0 commit comments

Comments
 (0)