mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 18:43:41 -05:00
Break init backend into its own package
This commit is contained in:
parent
8889e2df54
commit
4ebdb0fd38
2 changed files with 48 additions and 47 deletions
|
@ -14,7 +14,7 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package main
|
package initialize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -22,7 +22,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -33,45 +32,13 @@ import (
|
||||||
"maunium.net/go/gomuks/matrix"
|
"maunium.net/go/gomuks/matrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Information to find out exactly which commit gomuks was built from.
|
|
||||||
// These are filled at build time with the -X linker flag.
|
|
||||||
var (
|
|
||||||
Tag = "unknown"
|
|
||||||
Commit = "unknown"
|
|
||||||
BuildTime = "unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Version is the version number of gomuks. Changed manually when making a release.
|
|
||||||
Version = "0.3.0"
|
|
||||||
// VersionString is the gomuks version, plus commit information. Filled in init() using the build-time values.
|
|
||||||
VersionString = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if len(Tag) > 0 && Tag[0] == 'v' {
|
|
||||||
Tag = Tag[1:]
|
|
||||||
}
|
|
||||||
if Tag != Version {
|
|
||||||
suffix := ""
|
|
||||||
if !strings.HasSuffix(Version, "+dev") {
|
|
||||||
suffix = "+dev"
|
|
||||||
}
|
|
||||||
if len(Commit) > 8 {
|
|
||||||
Version = fmt.Sprintf("%s%s.%s", Version, suffix, Commit[:8])
|
|
||||||
} else {
|
|
||||||
Version = fmt.Sprintf("%s%s.unknown", Version, suffix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VersionString = fmt.Sprintf("gomuks %s (%s with %s)", Version, BuildTime, runtime.Version())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gomuks is the wrapper for everything.
|
// Gomuks is the wrapper for everything.
|
||||||
type Gomuks struct {
|
type Gomuks struct {
|
||||||
ui ifc.GomuksUI
|
ui ifc.GomuksUI
|
||||||
matrix *matrix.Container
|
matrix *matrix.Container
|
||||||
config *config.Config
|
config *config.Config
|
||||||
stop chan bool
|
stop chan bool
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGomuks creates a new Gomuks instance with everything initialized,
|
// NewGomuks creates a new Gomuks instance with everything initialized,
|
||||||
|
@ -94,7 +61,7 @@ func NewGomuks(uiProvider ifc.UIProvider, configDir, dataDir, cacheDir, download
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gmx *Gomuks) Version() string {
|
func (gmx *Gomuks) Version() string {
|
||||||
return Version
|
return gmx.version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save saves the active session and message history.
|
// Save saves the active session and message history.
|
48
main.go
48
main.go
|
@ -29,11 +29,45 @@ import (
|
||||||
flag "maunium.net/go/mauflag"
|
flag "maunium.net/go/mauflag"
|
||||||
|
|
||||||
"maunium.net/go/gomuks/debug"
|
"maunium.net/go/gomuks/debug"
|
||||||
|
"maunium.net/go/gomuks/initialize"
|
||||||
ifc "maunium.net/go/gomuks/interface"
|
ifc "maunium.net/go/gomuks/interface"
|
||||||
"maunium.net/go/gomuks/matrix"
|
"maunium.net/go/gomuks/matrix"
|
||||||
"maunium.net/go/gomuks/ui"
|
"maunium.net/go/gomuks/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Information to find out exactly which commit gomuks was built from.
|
||||||
|
// These are filled at build time with the -X linker flag.
|
||||||
|
var (
|
||||||
|
Tag = "unknown"
|
||||||
|
Commit = "unknown"
|
||||||
|
BuildTime = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Version is the version number of gomuks. Changed manually when making a release.
|
||||||
|
Version = "0.3.0"
|
||||||
|
// VersionString is the gomuks version, plus commit information. Filled in init() using the build-time values.
|
||||||
|
VersionString = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if len(Tag) > 0 && Tag[0] == 'v' {
|
||||||
|
Tag = Tag[1:]
|
||||||
|
}
|
||||||
|
if Tag != Version {
|
||||||
|
suffix := ""
|
||||||
|
if !strings.HasSuffix(Version, "+dev") {
|
||||||
|
suffix = "+dev"
|
||||||
|
}
|
||||||
|
if len(Commit) > 8 {
|
||||||
|
Version = fmt.Sprintf("%s%s.%s", Version, suffix, Commit[:8])
|
||||||
|
} else {
|
||||||
|
Version = fmt.Sprintf("%s%s.unknown", Version, suffix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VersionString = fmt.Sprintf("gomuks %s (%s with %s)", Version, BuildTime, runtime.Version())
|
||||||
|
}
|
||||||
|
|
||||||
var MainUIProvider ifc.UIProvider = ui.NewGomuksUI
|
var MainUIProvider ifc.UIProvider = ui.NewGomuksUI
|
||||||
|
|
||||||
var wantVersion = flag.MakeFull("v", "version", "Show the version of gomuks", "false").Bool()
|
var wantVersion = flag.MakeFull("v", "version", "Show the version of gomuks", "false").Bool()
|
||||||
|
@ -123,19 +157,19 @@ func main() {
|
||||||
debug.Print("Download directory:", downloadDir)
|
debug.Print("Download directory:", downloadDir)
|
||||||
|
|
||||||
matrix.SkipVersionCheck = *skipVersionCheck
|
matrix.SkipVersionCheck = *skipVersionCheck
|
||||||
gmx := NewGomuks(MainUIProvider, configDir, dataDir, cacheDir, downloadDir, *logInForTransfer)
|
gmx := initialize.NewGomuks(MainUIProvider, configDir, dataDir, cacheDir, downloadDir, *logInForTransfer)
|
||||||
|
|
||||||
if *clearCache {
|
if *clearCache {
|
||||||
debug.Print("Clearing cache as requested by CLI flag")
|
debug.Print("Clearing cache as requested by CLI flag")
|
||||||
gmx.config.Clear()
|
gmx.Config().Clear()
|
||||||
fmt.Printf("Cleared cache at %s\n", gmx.config.CacheDir)
|
fmt.Printf("Cleared cache at %s\n", gmx.Config().CacheDir)
|
||||||
return
|
return
|
||||||
} else if *clearData {
|
} else if *clearData {
|
||||||
debug.Print("Clearing all data as requested by CLI flag")
|
debug.Print("Clearing all data as requested by CLI flag")
|
||||||
gmx.config.Clear()
|
gmx.Config().Clear()
|
||||||
gmx.config.ClearData()
|
gmx.Config().ClearData()
|
||||||
_ = os.RemoveAll(gmx.config.Dir)
|
_ = os.RemoveAll(gmx.Config().Dir)
|
||||||
fmt.Printf("Cleared cache at %s, data at %s and config at %s\n", gmx.config.CacheDir, gmx.config.DataDir, gmx.config.Dir)
|
fmt.Printf("Cleared cache at %s, data at %s and config at %s\n", gmx.Config().CacheDir, gmx.Config().DataDir, gmx.Config().Dir)
|
||||||
return
|
return
|
||||||
} else if *logInForTransfer {
|
} else if *logInForTransfer {
|
||||||
debug.Print("Initializing in headless mode as requested by CLI flag")
|
debug.Print("Initializing in headless mode as requested by CLI flag")
|
||||||
|
|
Loading…
Add table
Reference in a new issue