-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.go
45 lines (34 loc) · 838 Bytes
/
spec.go
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
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/user"
nuget "github.com/soloworks/go-nuget-utils"
"github.com/urfave/cli"
)
func cliSampleNuSpec(c *cli.Context) error {
// Get current user details
user, err := user.Current()
checkError(err)
// Get the NuSpec
ns := nuget.SampleNuSpec(c.Args().First(), user.Name)
// Set filename string
fn := ns.Meta.ID + ".nuspec"
// Check if file exists and -Force isn't active
if _, err := os.Stat(fn); !os.IsNotExist(err) {
if !c.Bool("Force") {
return errors.New("'" + fn + "' already exists, use -Force to overwrite it.")
}
}
// Convert to []byte
b, err := ns.ToBytes()
checkError(err)
// Write to filesystem
err = ioutil.WriteFile(fn, b, 0644)
checkError(err)
// Echo out message
fmt.Println("Created: '" + fn + "' successfully.")
return nil
}