-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2398 from andydotxyz/feature/metadata
Feature/metadata
- Loading branch information
Showing
29 changed files
with
4,128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package metadata | ||
|
||
// FyneApp describes the top level metadata for building a fyne application | ||
type FyneApp struct { | ||
Website string `toml:",omitempty"` | ||
Details AppDetails | ||
} | ||
|
||
// AppDetails describes the build information, this group may be OS or arch specific | ||
type AppDetails struct { | ||
Icon string `toml:",omitempty"` | ||
Name, ID string `toml:",omitempty"` | ||
Version string `toml:",omitempty"` | ||
Build int `toml:",omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package metadata | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
// Load attempts to read a FyneApp metadata from the provided reader. | ||
// If this cannot be done an error will be returned. | ||
func Load(r io.Reader) (*FyneApp, error) { | ||
str, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data FyneApp | ||
if _, err := toml.Decode(string(str), &data); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &data, nil | ||
} | ||
|
||
// LoadStandard attempts to read a FyneApp metadata from the `FyneApp.toml` file in the specified dir. | ||
// If the file cannot be found or parsed an error will be returned. | ||
func LoadStandard(dir string) (*FyneApp, error) { | ||
path := filepath.Join(dir, "FyneApp.toml") | ||
r, err := os.Open(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer r.Close() | ||
return Load(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package metadata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadAppMetadata(t *testing.T) { | ||
r, err := os.Open("./testdata/FyneApp.toml") | ||
assert.Nil(t, err) | ||
defer r.Close() | ||
|
||
data, err := Load(r) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "https://apps.fyne.io", data.Website) | ||
assert.Equal(t, "io.fyne.fyne", data.Details.ID) | ||
assert.Equal(t, "v1.0", data.Details.Version) | ||
assert.Equal(t, 1, data.Details.Build) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package metadata | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
// Save attempts to write a FyneApp metadata to the provided writer. | ||
// If the encoding fails an error will be returned. | ||
func Save(f *FyneApp, w io.Writer) error { | ||
var buf bytes.Buffer | ||
e := toml.NewEncoder(&buf) | ||
err := e.Encode(f) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = w.Write(buf.Bytes()) | ||
return err | ||
} | ||
|
||
// SaveStandard attempts to save a FyneApp metadata to the `FyneApp.toml` file in the specified dir. | ||
// If the file cannot be written or encoding fails an error will be returned. | ||
func SaveStandard(f *FyneApp, dir string) error { | ||
path := filepath.Join(dir, "FyneApp.toml") | ||
w, err := os.Create(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer w.Close() | ||
return Save(f, w) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package metadata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSaveAppMetadata(t *testing.T) { | ||
r, err := os.Open("./testdata/FyneApp.toml") | ||
assert.Nil(t, err) | ||
data, err := Load(r) | ||
_ = r.Close() | ||
assert.Nil(t, err) | ||
assert.Equal(t, 1, data.Details.Build) | ||
|
||
data.Details.Build++ | ||
|
||
versionPath := "./testdata/Version.toml" | ||
w, err := os.Create(versionPath) | ||
assert.Nil(t, err) | ||
err = Save(data, w) | ||
assert.Nil(t, err) | ||
defer func() { | ||
os.Remove(versionPath) | ||
}() | ||
_ = w.Close() | ||
|
||
r, err = os.Open(versionPath) | ||
assert.Nil(t, err) | ||
defer r.Close() | ||
|
||
data2, err := Load(r) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 2, data2.Details.Build) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Website = "https://apps.fyne.io" | ||
|
||
[Details] | ||
Name = "Fyne App" | ||
ID = "io.fyne.fyne" | ||
Icon = "https://conf.fyne.io/assets/img/fyne.png" | ||
Version = "v1.0" | ||
Build = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.