mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(init): add subdirectory prompt for source path (#78)
Implemented Subdirectory Specification for Source
This commit is contained in:
+37
-7
@@ -12,7 +12,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/term"
|
||||
"skillshare/internal/config"
|
||||
gitops "skillshare/internal/git"
|
||||
"skillshare/internal/install"
|
||||
@@ -20,6 +19,8 @@ import (
|
||||
ssync "skillshare/internal/sync"
|
||||
"skillshare/internal/ui"
|
||||
"skillshare/internal/utils"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const skillshareSkillSource = "github.com/runkids/skillshare/skills/skillshare"
|
||||
@@ -402,18 +403,28 @@ func performFreshInit(opts *initOptions, home string) error {
|
||||
},
|
||||
}
|
||||
|
||||
if opts.dryRun {
|
||||
summarizeInitConfig(cfg)
|
||||
} else if err := cfg.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initialize git in source directory for safety
|
||||
initGitIfNeeded(sourcePath, opts.dryRun, opts.initGit, opts.noGit)
|
||||
|
||||
// Set up git remote for cross-machine sync
|
||||
setupGitRemote(sourcePath, opts.remoteURL, opts.dryRun)
|
||||
|
||||
// Prompt user for subdirectory
|
||||
subDir := useSourceSubdir()
|
||||
if subDir != "" {
|
||||
sourcePath = filepath.Join(sourcePath, subDir)
|
||||
if err := createSourceDir(sourcePath, opts.dryRun); err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Source = sourcePath
|
||||
}
|
||||
|
||||
if opts.dryRun {
|
||||
summarizeInitConfig(cfg)
|
||||
} else if err := cfg.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Install built-in skillshare skill (opt-in)
|
||||
installSkillIfNeeded(sourcePath, opts.dryRun, opts.initSkill, opts.noSkill)
|
||||
|
||||
@@ -1219,6 +1230,25 @@ func tryPullAfterRemoteSetup(sourcePath, remoteURL string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Specify a subdirectory to be the source and store the skills
|
||||
// This allows users to have skills stored in a subdirectory of their repo and not the root
|
||||
// Returns a string representing the name of the subdirectory, empty if none was selected
|
||||
func useSourceSubdir() string {
|
||||
fmt.Println()
|
||||
fmt.Println(" Specifying a subdirectory as the source will store skills in the subdirectory (e.g. skills/) instead of in the root")
|
||||
fmt.Print(" Specify a subdirectory as the source (e.g. skills)? [y/N]: ")
|
||||
var input string
|
||||
fmt.Scanln(&input)
|
||||
input = strings.ToLower(strings.TrimSpace(input))
|
||||
|
||||
if input == "y" || input == "yes" {
|
||||
fmt.Print(" Enter subdirectory name: ")
|
||||
dirNameInput, _ := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
return strings.TrimSpace(dirNameInput)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
const fallbackSkillContent = `---
|
||||
name: skillshare
|
||||
description: Manage and sync skills across AI CLI tools
|
||||
|
||||
Reference in New Issue
Block a user