-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
138 lines (111 loc) · 3.98 KB
/
Program.fs
File metadata and controls
138 lines (111 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
open System.IO
open System.Text.Json
open System.Text.Json.Serialization
open Common
open FSLogger
module C = Common
open Common.Common
type DateTime = System.DateTime
open Argu
module Str = String
module Dir = Directory
type CliArguments =
| [<CliPrefix(CliPrefix.None)>] Add of name: string
| [<CliPrefix(CliPrefix.None)>] Diff of newPath: string * oldPath: string
| [<CliPrefix(CliPrefix.None)>] Merge of package: string
| [<CliPrefix(CliPrefix.None)>] List
| [<CliPrefix(CliPrefix.None)>] Test
| [<CliPrefix(CliPrefix.None)>] Version
| [<CliPrefix(CliPrefix.None)>] Sync of newPath: string * oldPath: string
| Path of path: string
interface IArgParserTemplate with
member this.Usage =
match this with
| Add name ->
"添加當前狀態"
| Diff _ -> "比較兩個狀態,生成補丁包"
| Merge _ -> "合併補丁包"
| Path _ -> "Path"
| List -> "列出狀態"
| Sync _ -> "Sync"
| Test -> "Test"
| Version -> "版本號"
[<EntryPoint>]
let main argv =
printfn "argv: %A" argv
Common.logger <- Logger.ColorConsole
logger.I $"argv: {argv}"
let parser = ArgumentParser.Create<CliArguments>(programName = "dir-diff.exe")
let result = parser.Parse argv
let all = result.GetAllResults()
let history = Path.join Dir.current ".history"
let addParam = result.TryGetResult Add
let diffParam = result.TryGetResult Diff
let mergeParam = result.TryGetResult Merge
let listParam = result.TryGetResult List
let syncParam = result.TryGetResult Sync
let testParam = result.TryGetResult Test
let versionParam = result.TryGetResult Version
if addParam.IsSome then
let path = Dir.current
let dest = Path.join history addParam.Value
if Dir.exists dest then
printfn "%s exists" dest
exit 1
Dir.create dest
let whiteList = Path.join3 history ".config" "white_list.txt"
let content =
match whiteList |> File.exists with
| true ->
Some <| File.readAllLines whiteList
| false -> None
Diff.current (fun p _ _ ->
let h = p |> Str.startsWith ".history" |> not
match content with
| Some c ->
Array.exists (p |> Str.startsWith) c && h
| None -> h) path dest
exit 0
if diffParam.IsSome then
let history = Path.join Dir.current ".history"
let path = Dir.current
let newPath, oldPath = diffParam.Value
let dest = Path.join3 history ".diff" <| newPath + "-" + oldPath
let newPath = Path.join history newPath
let oldPath = Path.join history oldPath
Dir.create dest
Diff.diff path dest newPath oldPath
exit 0
if mergeParam.IsSome then
let path = Dir.current
logger.I $"path: {path}"
Diff.merge path mergeParam.Value
exit 0
if listParam.IsSome then
let history = Path.join Dir.current ".history"
let dirs =
Directory.GetDirectories history
|> Array.map (fun i -> i, DirectoryInfo.create i)
|> Array.sortByDescending (fun (_, v) -> v.LastWriteTime)
for i, info in dirs do
let relativePath = Path.relativePath history i
if relativePath |> Str.startsWith ".diff" |> not then
printfn "path: %A writeTime: %A" relativePath <| info.LastWriteTime
exit 0
if syncParam.IsSome then
let newPath, oldPath = syncParam.Value
if Dir.exists newPath |> not then
failwith <| newPath + "not exists"
Diff.sync newPath oldPath
exit 0
if testParam.IsSome then
failwith "test"
Diff.test
exit 0
if versionParam.IsSome then
printfn "version: %s" "0.1.0.240328"
exit 0
printfn "%s" <| parser.PrintUsage()
exit 1
printfn "%A" result
0