readme
This commit is contained in:
parent
7d8a3440b3
commit
777fa30c40
39
README.md
39
README.md
|
@ -1,16 +1,35 @@
|
||||||
# list version
|
|
||||||
|
|
||||||
manage file version caches
|
# 项目描述:
|
||||||
|
|
||||||
|
list version 工具旨在高效地管理和控制项目中的文件版本。它允许用户跟踪文件的不同版本,轻松地将新版本添加到缓存中,从缓存中删除不需要的版本,并根据需要从缓存中提取特定版本的文件。该工具对于开发人员、设计师或任何需要维护文件更改历史记录以进行审计、协作或避免意外覆盖重要数据的人来说特别有用。
|
||||||
|
|
||||||
usage:
|
使用说明(中文版):
|
||||||
|
|
||||||
```
|
|
||||||
________________________________________________________
|
________________________________________________________
|
||||||
[h] print this
|
[h] 显示此帮助菜单
|
||||||
[l] list verisons. [lv l xx.txt]
|
[l] 列出文件的版本。 [lv l 文件名.txt] 或列出当前目录下所有文件的版本 [lv l .]
|
||||||
[a] add file to cache. [lv a xx.txt xxx]
|
[a] 将文件的新版本添加到缓存中。 [lv a 文件名.txt 版本描述]
|
||||||
[d] remove version from cache. [lv d xx.txt 1]
|
[d] 从缓存中删除文件的特定版本。 [lv d 文件名.txt 版本号]
|
||||||
[r] extract file version from cache. [lv r xx.txt 1]
|
[r] 从缓存中提取(还原)文件的特定版本。 [lv r 文件名.txt 版本号]
|
||||||
|
--------------------------------------------------------
|
||||||
|
关键改进:
|
||||||
|
|
||||||
|
命令描述清晰:每个命令都附有更简洁明了的描述,帮助用户快速理解其功能。
|
||||||
|
文件和版本标识符:使用文件名.txt和版本号/版本描述作为占位符,使用户能够清楚地知道每个命令需要哪些信息。
|
||||||
|
列表命令增强:明确提到[lv l .]选项,表明用户可以列出当前目录下所有文件的版本,提高了该功能的可发现性。
|
||||||
|
命令命名一致性:所有命令均采用[lv ...]格式,确保了命令使用的一致性,简化了用户的操作。
|
||||||
|
通过提供直观的命令和强大的版本控制功能,list version 工具使用户能够自信且轻松地管理他们的文件。
|
||||||
|
|
||||||
|
# Project Description(GPT):
|
||||||
|
|
||||||
|
The list version tool is designed to efficiently manage and version control files within a project. It allows users to keep track of different versions of files, easily add new versions to the cache, remove unwanted versions, and retrieve specific versions as needed. This tool is particularly useful for developers, designers, or anyone who needs to maintain a history of file changes for auditing, collaboration, or simply to avoid accidental overwriting of important data.
|
||||||
|
|
||||||
|
Optimized Usage Instructions:
|
||||||
|
|
||||||
|
________________________________________________________
|
||||||
|
[h] Display this help menu
|
||||||
|
[l] List versions of a file. [lv l filename.txt] or to list all versions in the current directory [lv l .]
|
||||||
|
[a] Add a new version of a file to the cache. [lv a filename.txt version_description]
|
||||||
|
[d] Remove a specific version of a file from the cache. [lv d filename.txt version_number]
|
||||||
|
[r] Retrieve (extract) a specific version of a file from the cache. [lv r filename.txt version_number]
|
||||||
--------------------------------------------------------
|
--------------------------------------------------------
|
||||||
```
|
|
|
@ -42,7 +42,13 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func v() {
|
func v() {
|
||||||
storage.All()
|
path := ""
|
||||||
|
|
||||||
|
if len(os.Args) > 2 {
|
||||||
|
path = os.Args[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.All(path == "." || path == "./")
|
||||||
}
|
}
|
||||||
|
|
||||||
func h() {
|
func h() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.dengqn.com/dqn/listversion/util"
|
"git.dengqn.com/dqn/listversion/util"
|
||||||
)
|
)
|
||||||
|
@ -36,7 +37,7 @@ type Version struct {
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func All() (all []FileMeta) {
|
func All(current bool) (all []FileMeta) {
|
||||||
root, _ := os.UserConfigDir()
|
root, _ := os.UserConfigDir()
|
||||||
|
|
||||||
appRoot, err := os.Open(path.Join(root, "list-version"))
|
appRoot, err := os.Open(path.Join(root, "list-version"))
|
||||||
|
@ -54,8 +55,10 @@ func All() (all []FileMeta) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sub, _ := appRoot.Readdir(0)
|
sub, _ := appRoot.Readdir(0)
|
||||||
|
|
||||||
|
// filter this wd
|
||||||
pwd, _ := os.Getwd()
|
pwd, _ := os.Getwd()
|
||||||
log.Println("pwd:", pwd)
|
// log.Println("pwd:", pwd)
|
||||||
for _, fi := range sub {
|
for _, fi := range sub {
|
||||||
var meta FileMeta
|
var meta FileMeta
|
||||||
|
|
||||||
|
@ -64,11 +67,27 @@ func All() (all []FileMeta) {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer fileMeta.Close()
|
|
||||||
// read meta.json
|
// read meta.json
|
||||||
|
|
||||||
buf, _ := io.ReadAll(fileMeta)
|
buf, _ := io.ReadAll(fileMeta)
|
||||||
json.Unmarshal(buf, &meta)
|
json.Unmarshal(buf, &meta)
|
||||||
|
fileMeta.Close()
|
||||||
|
|
||||||
|
if current {
|
||||||
|
if !strings.HasPrefix(meta.AbsolutePath, pwd) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(meta.Versions) == 0 {
|
||||||
|
// rm
|
||||||
|
err = os.RemoveAll(path.Join(root, "list-version", fi.Name()))
|
||||||
|
if err != nil {
|
||||||
|
log.Panicln(err.Error())
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("[%d] %s\n", len(meta.Versions), meta.AbsolutePath)
|
fmt.Printf("[%d] %s\n", len(meta.Versions), meta.AbsolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue