Skip to content

Commit

Permalink
change some logging to debug level
Browse files Browse the repository at this point in the history
  • Loading branch information
dperny committed Feb 13, 2021
1 parent d95048f commit ce09d65
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 25 deletions.
Binary file modified bta-wiki-import.exe
Binary file not shown.
1 change: 1 addition & 0 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ func Run() {
RootCmd.AddCommand(ExportMechCmd)
RootCmd.AddCommand(ParseCmd)
RootCmd.AddCommand(ImportCmd)
RootCmd.AddCommand(LintCmd)
RootCmd.Execute()
}
33 changes: 21 additions & 12 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ func makeFilename(desc export.Description) string {
return fmt.Sprintf("%s.wiki", desc.Id)
}

var LintCmd = &cobra.Command{
Use: "lint <mod directory>",
Short: "parse the mod directory but do not write out wikitext",
Run: func(cmd *cobra.Command, args []string) {
modDirectory := args[0]

// walk the mod directory
_, errs := export.WalkModsDirectory(modDirectory)
if len(errs) > 0 {
fmt.Printf("%d errors when parsing mods", len(errs))
os.Exit(1)
}
},
}

var ExportCmd = &cobra.Command{
Use: "export <mod directory> <destination>",
Short: "export all mod data to wikitext",
Expand All @@ -39,7 +54,7 @@ var ExportCmd = &cobra.Command{

filename := fmt.Sprintf("MechDef_%s_%s.wiki", mech.Chassis.Description.Name, variant)

logrus.Infof("Writing mech wiki %s", filename)
logrus.Debugf("Writing mech wiki %s", filename)

path := filepath.Join(destination, filename)

Expand Down Expand Up @@ -85,7 +100,7 @@ var ExportCmd = &cobra.Command{
}
filename := makeFilename(gear.Description)

logrus.Infof("Writing gear wiki %s", filename)
logrus.Debugf("Writing gear wiki %s", filename)

path := filepath.Join(destination, filename)

Expand Down Expand Up @@ -116,7 +131,7 @@ var ExportCmd = &cobra.Command{
}
filename := makeFilename(weapon.Description)

logrus.Infof("Writing weapon wiki %s", filename)
logrus.Debugf("Writing weapon wiki %s", filename)

path := filepath.Join(destination, filename)

Expand Down Expand Up @@ -147,13 +162,13 @@ var ExportCmd = &cobra.Command{
}
filename := makeFilename(jumpjet.Description)

logrus.Infof("Writing jumpjet wiki %s", filename)
logrus.Debugf("Writing jumpjet wiki %s", filename)

path := filepath.Join(destination, filename)

file, err := os.Create(path)
if err != nil {
logrus.Infof("Error opening %s: %s", path, err)
logrus.Errorf("Error opening %s: %s", path, err)
continue
}

Expand All @@ -178,7 +193,7 @@ var ExportCmd = &cobra.Command{
}
filename := makeFilename(ammo.AmmunitionBox.Description)

logrus.Infof("Writing ammo wiki %s\n", filename)
logrus.Debugf("Writing ammo wiki %s\n", filename)

path := filepath.Join(destination, filename)

Expand Down Expand Up @@ -255,9 +270,3 @@ var ExportGearCmd = &cobra.Command{
return nil
},
}

/*
func init() {
ExportCmd.PersistentFlags().String(&mechfile, "mechfile", "a file containing a list of mechs to export")
}
*/
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

var (
flagColor bool
flagDebug bool
)

var RootCmd = &cobra.Command{
Expand All @@ -16,9 +17,13 @@ var RootCmd = &cobra.Command{
if flagColor {
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
}
if flagDebug {
logrus.SetLevel(logrus.DebugLevel)
}
},
}

func init() {
RootCmd.PersistentFlags().BoolVar(&flagColor, "color", true, "enable color logging")
RootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "enable debug-level logging")
}
4 changes: 4 additions & 0 deletions export/chassisdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (cd ChassisDef) ToWiki() string {
wt.AddArg("MeleeInstability", cd.MeleeInstability)
wt.AddArg("MeleeToHitModifier", cd.MeleeToHitModifier)

if len(cd.ChassisTags.Items) > 0 {
wt.AddArg("ChassisTags", strings.Join(cd.ChassisTags.Items, ","))
}

locations := make([]string, len(cd.Locations))
for i, location := range cd.Locations {
locations[i] = location.ToWiki(cd.Description.Id)
Expand Down
26 changes: 13 additions & 13 deletions export/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WalkMechs(modpath string, chassisdefPaths, mechdefPaths []string) (map[stri
}
}
}
logrus.Infof("parsed %d chassisdefs", len(chassisDefs))
logrus.Debugf("parsed %d chassisdefs", len(chassisDefs))

for _, mechdefPath := range mechdefPaths {
p := filepath.Join(modpath, mechdefPath)
Expand Down Expand Up @@ -120,7 +120,7 @@ func WalkMechs(modpath string, chassisdefPaths, mechdefPaths []string) (map[stri
}
}

logrus.Infof("parsed %d mechdefs", len(mechs))
logrus.Debugf("parsed %d mechdefs", len(mechs))

return mechs, errors
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func WalkGear(modpath string, gearPaths []string) ([]Gear, []error) {
}
}

logrus.Infof("parsed %d gear", len(allGear))
logrus.Debugf("parsed %d gear", len(allGear))
return allGear, errors
}

Expand Down Expand Up @@ -194,7 +194,7 @@ func WalkJumpJets(modpath string, jumpjetPaths []string) ([]JumpJet, []error) {
}
}

logrus.Infof("parsed %d jumpjets", len(jumpjets))
logrus.Debugf("parsed %d jumpjets", len(jumpjets))
return jumpjets, errors
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func WalkWeapons(modpath string, weaponPaths []string) ([]Weapon, []error) {
}
}

logrus.Infof("parsed %d weapons", len(weapons))
logrus.Debugf("parsed %d weapons", len(weapons))
return weapons, errors
}

Expand Down Expand Up @@ -362,27 +362,27 @@ func WalkMod(modpath string) (ModData, []error) {
switch manifest.Type {
case ManifestTypeChassisDef:
chassisdefPaths = append(chassisdefPaths, manifest.Path)
logrus.Infof("mod defines chassisdefs at %s", manifest.Path)
logrus.Debugf("mod defines chassisdefs at %s", manifest.Path)
case ManifestTypeMechDef:
mechdefPaths = append(mechdefPaths, manifest.Path)
logrus.Infof("mod defines mechdefs at %s", manifest.Path)
logrus.Debugf("mod defines mechdefs at %s", manifest.Path)
case ManifestTypeHeatsink, ManifestTypeUpgrade:
gearPaths = append(gearPaths, manifest.Path)
logrus.Infof("mod defines %s at %s", manifest.Type, manifest.Path)
logrus.Debugf("mod defines %s at %s", manifest.Type, manifest.Path)
case ManifestTypeJumpJet:
jumpjetPaths = append(jumpjetPaths, manifest.Path)
logrus.Infof("mod define jump jets at %s", manifest.Type, manifest.Path)
logrus.Debugf("mod define jump jets at %s", manifest.Type, manifest.Path)
case ManifestTypeWeapon:
weaponPaths = append(weaponPaths, manifest.Path)
logrus.Infof("mod defines weapons at %s", manifest.Path)
logrus.Debugf("mod defines weapons at %s", manifest.Path)
case ManifestTypeAmmunitionBox:
ammoBoxPaths = append(ammoBoxPaths, manifest.Path)
logrus.Infof("mod defines ammo box at %s", manifest.Path)
logrus.Debugf("mod defines ammo box at %s", manifest.Path)
case ManifestTypeAmmunition:
ammoPaths = append(ammoPaths, manifest.Path)
logrus.Infof("mod defines ammo at %s", manifest.Path)
logrus.Debugf("mod defines ammo at %s", manifest.Path)
default:
logrus.Warnf("ignoring unknown manifest type %s", manifest.Type)
logrus.Debugf("ignoring unknown manifest type %s", manifest.Type)
}
}

Expand Down

0 comments on commit ce09d65

Please sign in to comment.