11package composer
22
33// Archive 创建项目的归档文件(不包含开发依赖)
4+ //
5+ // 参数:
6+ // - destination: 存储归档文件的目标目录路径
7+ //
8+ // 返回值:
9+ // - string: 归档命令的输出结果
10+ // - error: 如果创建归档过程中发生错误,则返回相应的错误信息
11+ //
12+ // 功能说明:
13+ //
14+ // 该方法创建当前项目的ZIP格式归档文件,不包含开发依赖。
15+ // 相当于执行`composer archive --format=zip --dir=destination`命令。
16+ //
17+ // 用法示例:
18+ //
19+ // output, err := comp.Archive("/path/to/output/dir")
20+ // if err != nil {
21+ // log.Fatalf("创建归档文件失败: %v", err)
22+ // }
23+ // fmt.Println("归档创建结果:", output)
424func (c * Composer ) Archive (destination string ) (string , error ) {
525 return c .Run ("archive" , "--format=zip" , "--dir=" + destination )
626}
727
828// ArchiveWithFormat 使用指定格式创建项目的归档文件
29+ //
30+ // 参数:
31+ // - destination: 存储归档文件的目标目录路径
32+ // - format: 归档文件格式,可以是"zip"或"tar"
33+ //
34+ // 返回值:
35+ // - string: 归档命令的输出结果
36+ // - error: 如果创建归档过程中发生错误,则返回相应的错误信息
37+ //
38+ // 功能说明:
39+ //
40+ // 该方法创建当前项目的归档文件,可以指定归档格式,不包含开发依赖。
41+ // 相当于执行`composer archive --format=[format] --dir=destination`命令。
42+ //
43+ // 用法示例:
44+ //
45+ // // 创建TAR格式归档
46+ // output, err := comp.ArchiveWithFormat("/path/to/output/dir", "tar")
47+ // if err != nil {
48+ // log.Fatalf("创建TAR归档文件失败: %v", err)
49+ // }
50+ // fmt.Println("归档创建结果:", output)
951func (c * Composer ) ArchiveWithFormat (destination string , format string ) (string , error ) {
1052 return c .Run ("archive" , "--format=" + format , "--dir=" + destination )
1153}
1254
1355// ArchiveWithOptions 使用自定义选项创建项目的归档文件
56+ //
57+ // 参数:
58+ // - destination: 存储归档文件的目标目录路径
59+ // - options: 归档选项的映射,键为选项名,值为选项值
60+ //
61+ // 返回值:
62+ // - string: 归档命令的输出结果
63+ // - error: 如果创建归档过程中发生错误,则返回相应的错误信息
64+ //
65+ // 功能说明:
66+ //
67+ // 该方法使用自定义选项创建当前项目的归档文件,提供最大的灵活性。
68+ //
69+ // 用法示例:
70+ //
71+ // // 使用多个自定义选项创建归档
72+ // options := map[string]string{
73+ // "format": "tar",
74+ // "file": "my-project.tar",
75+ // "ignore-filters": "",
76+ // }
77+ // output, err := comp.ArchiveWithOptions("/path/to/output/dir", options)
78+ // if err != nil {
79+ // log.Fatalf("创建归档文件失败: %v", err)
80+ // }
81+ // fmt.Println("归档创建结果:", output)
1482func (c * Composer ) ArchiveWithOptions (destination string , options map [string ]string ) (string , error ) {
1583 args := []string {"archive" , "--dir=" + destination }
1684
@@ -26,6 +94,35 @@ func (c *Composer) ArchiveWithOptions(destination string, options map[string]str
2694}
2795
2896// ArchivePackage 创建指定包的归档文件
97+ //
98+ // 参数:
99+ // - packageName: 要归档的包名,例如"symfony/console"
100+ // - version: 要归档的包版本,例如"v5.4.0",为空则使用最新版本
101+ // - destination: 存储归档文件的目标目录路径
102+ //
103+ // 返回值:
104+ // - string: 归档命令的输出结果
105+ // - error: 如果创建归档过程中发生错误,则返回相应的错误信息
106+ //
107+ // 功能说明:
108+ //
109+ // 该方法创建指定包的归档文件,可以指定包版本。
110+ // 相当于执行`composer archive packageName[=version] --dir=destination`命令。
111+ //
112+ // 用法示例:
113+ //
114+ // // 归档指定版本的包
115+ // output, err := comp.ArchivePackage("symfony/console", "v5.4.0", "/path/to/output/dir")
116+ // if err != nil {
117+ // log.Fatalf("创建包归档文件失败: %v", err)
118+ // }
119+ // fmt.Println("包归档创建结果:", output)
120+ //
121+ // // 归档最新版本的包
122+ // output, err = comp.ArchivePackage("symfony/console", "", "/path/to/output/dir")
123+ // if err != nil {
124+ // log.Fatalf("创建包归档文件失败: %v", err)
125+ // }
29126func (c * Composer ) ArchivePackage (packageName string , version string , destination string ) (string , error ) {
30127 args := []string {"archive" }
31128
@@ -41,6 +138,38 @@ func (c *Composer) ArchivePackage(packageName string, version string, destinatio
41138}
42139
43140// ArchivePackageWithOptions 使用自定义选项创建指定包的归档文件
141+ //
142+ // 参数:
143+ // - packageName: 要归档的包名,例如"symfony/console"
144+ // - version: 要归档的包版本,例如"v5.4.0",为空则使用最新版本
145+ // - destination: 存储归档文件的目标目录路径
146+ // - options: 归档选项的映射,键为选项名,值为选项值
147+ //
148+ // 返回值:
149+ // - string: 归档命令的输出结果
150+ // - error: 如果创建归档过程中发生错误,则返回相应的错误信息
151+ //
152+ // 功能说明:
153+ //
154+ // 该方法使用自定义选项创建指定包的归档文件,提供最大的灵活性。
155+ //
156+ // 用法示例:
157+ //
158+ // // 使用自定义选项归档指定版本的包
159+ // options := map[string]string{
160+ // "format": "tar",
161+ // "ignore-filters": "",
162+ // }
163+ // output, err := comp.ArchivePackageWithOptions(
164+ // "symfony/console",
165+ // "v5.4.0",
166+ // "/path/to/output/dir",
167+ // options,
168+ // )
169+ // if err != nil {
170+ // log.Fatalf("创建包归档文件失败: %v", err)
171+ // }
172+ // fmt.Println("包归档创建结果:", output)
44173func (c * Composer ) ArchivePackageWithOptions (packageName string , version string , destination string , options map [string ]string ) (string , error ) {
45174 args := []string {"archive" }
46175
0 commit comments