Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

NutFile.ReadFile()

  • Loading branch information...
commit f030cca82a0b8c71a0e86eaec94b698dc110a589 1 parent 9535cd3
@AlekSi authored
Showing with 24 additions and 3 deletions.
  1. +1 −0  CHANGELOG
  2. +14 −1 nut.go
  3. +9 −2 nut_test.go
View
1  CHANGELOG
@@ -6,6 +6,7 @@
* `nut pack` now includes files for all OSes.
+ New API for Spec: ReadFile().
+ New API for Nut: ReadFrom(), FilePath(), ImportPath().
+ + New API for NutFile: ReadFile().
* Fix bug with `nut get` and www.-prefixed hosts.
* Fix some issues on Windows.
* Fix -h and extra arguments handling.
View
15 nut.go
@@ -72,6 +72,8 @@ func (nut *Nut) ImportPath(prefix string) string {
// Read nut from directory: package from <dir> and spec from <dir>/<SpecFileName>.
func (nut *Nut) ReadFrom(dir string) (err error) {
+ // This method is called ReadFrom to prevent code n.ReadFrom(r) from calling n.Spec.ReadFrom(r).
+
// read package
pack, err := build.ImportDir(dir, 0)
if err != nil {
@@ -98,9 +100,20 @@ type NutFile struct {
// check interface
var (
_ io.ReaderFrom = &NutFile{}
- _ io.WriterTo = &NutFile{}
)
+// Reads nut from specified file.
+func (nf *NutFile) ReadFile(fileName string) (err error) {
+ f, err := os.Open(fileName)
+ if err != nil {
+ return
+ }
+ defer f.Close()
+
+ _, err = nf.ReadFrom(f)
+ return
+}
+
// ReadFrom reads nut from r until EOF.
// The return value n is the number of bytes read.
// Any error except io.EOF encountered during the read is also returned.
View
11 nut_test.go
@@ -31,7 +31,7 @@ func (f *N) SetUpTest(c *C) {
f.nf = nf
}
-func (f *N) TestNutFile(c *C) {
+func (f *N) TestNutFileReadFrom(c *C) {
c.Check(f.nf.Spec.Version.String(), Equals, "0.0.1")
c.Check(f.nf.Version.String(), Equals, "0.0.1")
c.Check(f.nf.Vendor, Equals, "debug")
@@ -53,7 +53,14 @@ func (f *N) TestNutFile(c *C) {
DeepEquals, names)
}
-func (f *N) TestNutDir(c *C) {
+func (f *N) TestNutFileReadFile(c *C) {
+ nf := new(NutFile)
+ err := nf.ReadFile("../test_nut1/test_nut1-0.0.1.nut")
+ c.Check(err, IsNil)
+ c.Check(nf, DeepEquals, f.nf)
+}
+
+func (f *N) TestNutReadFrom(c *C) {
pwd, err := os.Getwd()
c.Assert(err, IsNil)
c.Assert(os.Chdir("../test_nut1"), IsNil)
Please sign in to comment.
Something went wrong with that request. Please try again.