aboutsummaryrefslogtreecommitdiff
path: root/spdxconv.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-08 19:08:14 +0700
committerShulhan <ms@kilabit.info>2026-01-08 20:40:27 +0700
commita10b07ddbd21c7725df43f3e37b9d7709fbe66b7 (patch)
tree0d2704626e6b489658a1a068f85a8942c0a07fb6 /spdxconv.go
parent496c812f6e14b77408b71f7a35a3d755b8bbbf36 (diff)
downloadspdxconv-a10b07ddbd21c7725df43f3e37b9d7709fbe66b7.tar.xz
cmd/spdxconv: implement "init" command
The init command create the spdxconv configuration file in the current directory.
Diffstat (limited to 'spdxconv.go')
-rw-r--r--spdxconv.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/spdxconv.go b/spdxconv.go
index 3aaabf3..25ebec0 100644
--- a/spdxconv.go
+++ b/spdxconv.go
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
-// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
+// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
package spdxconv
@@ -14,6 +14,9 @@ import (
"git.sr.ht/~shulhan/pakakeh.go/lib/ini"
)
+// ConfigFile the file name for configuration file.
+const ConfigFile = `spdxconv.cfg`
+
// SPDXConv the main type for converting files to SPDX format.
type SPDXConv struct {
scm sourceCodeManagement
@@ -64,6 +67,12 @@ func Apply(path string) (err error) {
return nil
}
+// Init create the configuration file [ConfigFile] in the current directory.
+func Init() (err error) {
+ err = os.WriteFile(ConfigFile, []byte(configTemplate), 0600)
+ return err
+}
+
// New initialize new instance of SPDXConv.
func New(path string) (conv *SPDXConv, err error) {
var logp = `New`
@@ -108,11 +117,10 @@ func New(path string) (conv *SPDXConv, err error) {
return conv, nil
}
-// loadConfig load the program configuration from file `spdxconv.cfg` in the
-// current directory.
+// loadConfig load the program [ConfigFile] from the current directory.
func (conv *SPDXConv) loadConfig(dir string) (err error) {
var logp = `loadConfig`
- var pathcfg = filepath.Join(dir, `spdxconv.cfg`)
+ var pathcfg = filepath.Join(dir, ConfigFile)
var rawcfg []byte
rawcfg, err = os.ReadFile(pathcfg)
if err != nil {
@@ -182,7 +190,7 @@ func (conv *SPDXConv) scanFiles(listDir []string) (listFile []string, err error)
var commonIgnore = map[string]struct{}{
`.git`: struct{}{},
`node_modules`: struct{}{},
- `spdxconv.cfg`: struct{}{},
+ ConfigFile: struct{}{},
`vendor`: struct{}{},
}
var suffixLicense = `.license`