Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

- ✨ `Makefile` #277
- 🎨 Improve `mas list` command output #278

## [v1.7.0] 🛍 Purchase Command - 2020-05-24

Expand Down
11 changes: 4 additions & 7 deletions MasKit/Commands/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ public struct ListCommand: CommandProtocol {
print("No installed apps found")
return .success(())
}
for product in products {
var appName = product.appName
if appName == "" {
appName = product.bundleIdentifier
}
print("\(product.itemIdentifier) \(appName) (\(product.bundleVersion))")
}

let output = AppListFormatter.format(products: products)
print(output)

return .success(())
}
}
36 changes: 36 additions & 0 deletions MasKit/Formatters/AppListFormatter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AppListFormatter.swift
// MasKit
//
// Created by Ben Chatelain on 6/7/20.
// Copyright © 2019 mas-cli. All rights reserved.
//

import Foundation

/// Formats text output for the search command.
struct AppListFormatter {
/// Formats text output with list results.
///
/// - Parameter products: List of sortware products app data.
/// - Returns: Multiliune text outoutp.
static func format(products: [SoftwareProduct]) -> String {
// find longest appName for formatting, default 50
let minWidth = 50
let maxLength = products.map { $0.appNameOrBbundleIdentifier }
.max(by: { $1.count > $0.count })?.count
?? minWidth

var output: String = ""

for product in products {
let appId = product.itemIdentifier
let appName = product.appNameOrBbundleIdentifier.padding(toLength: maxLength, withPad: " ", startingAt: 0)
let version = product.bundleVersion

output += "\(appId) \(appName) (\(version))\n"
}

return output.trimmingCharacters(in: .newlines)
}
}
5 changes: 5 additions & 0 deletions MasKit/Models/SoftwareProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ extension SoftwareProduct {
&& lhs.bundleVersion == rhs.bundleVersion
&& lhs.itemIdentifier == rhs.itemIdentifier
}

/// Returns bundleIdentifier if appName is empty string.
var appNameOrBbundleIdentifier: String {
appName == "" ? bundleIdentifier : appName
}
}
4 changes: 4 additions & 0 deletions mas-cli.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
F85DA8B0240C32FA00FE5650 /* SoftwareMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85DA8AF240C32FA00FE5650 /* SoftwareMap.swift */; };
F85DA8B2240CBAFE00FE5650 /* CKSoftwareMap+SoftwareMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85DA8B1240CBAFE00FE5650 /* CKSoftwareMap+SoftwareMap.swift */; };
F88CB8E12404DAAD00B691B5 /* OpenSystemCommandSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = F88CB8E02404DAAD00B691B5 /* OpenSystemCommandSpec.swift */; };
F8A41ECE248D76CB00D374CF /* AppListFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A41ECD248D76CB00D374CF /* AppListFormatter.swift */; };
F8FB715B20F2B41400F56FDC /* MasKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8FB715220F2B41400F56FDC /* MasKit.framework */; };
F8FB716220F2B41400F56FDC /* MasKit.h in Headers */ = {isa = PBXBuildFile; fileRef = F8FB715420F2B41400F56FDC /* MasKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
F8FB716A20F2B4DD00F56FDC /* Downloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238A1B87569C00AE40CD /* Downloader.swift */; };
Expand Down Expand Up @@ -326,6 +327,7 @@
F85DA8AF240C32FA00FE5650 /* SoftwareMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoftwareMap.swift; sourceTree = "<group>"; };
F85DA8B1240CBAFE00FE5650 /* CKSoftwareMap+SoftwareMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CKSoftwareMap+SoftwareMap.swift"; sourceTree = "<group>"; };
F88CB8E02404DAAD00B691B5 /* OpenSystemCommandSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSystemCommandSpec.swift; sourceTree = "<group>"; };
F8A41ECD248D76CB00D374CF /* AppListFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppListFormatter.swift; sourceTree = "<group>"; };
F8FB715220F2B41400F56FDC /* MasKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MasKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F8FB715420F2B41400F56FDC /* MasKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MasKit.h; sourceTree = "<group>"; };
F8FB715520F2B41400F56FDC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -527,6 +529,7 @@
isa = PBXGroup;
children = (
B576FE2921E4240B0016B39D /* AppInfoFormatter.swift */,
F8A41ECD248D76CB00D374CF /* AppListFormatter.swift */,
B576FE3221E985250016B39D /* SearchResultFormatter.swift */,
EDCBF9541D89CFC7000039C6 /* Utilities.swift */,
);
Expand Down Expand Up @@ -1029,6 +1032,7 @@
B576FE0021E113610016B39D /* NetworkSession.swift in Sources */,
B5DBF80D21DEE4E600F3B151 /* Open.swift in Sources */,
B576FDF721E107AA0016B39D /* OpenSystemCommand.swift in Sources */,
F8A41ECE248D76CB00D374CF /* AppListFormatter.swift in Sources */,
F8FB717420F2B4DD00F56FDC /* Outdated.swift in Sources */,
75FB3E761F9F7841005B6F20 /* Purchase.swift in Sources */,
F8FB716C20F2B4DD00F56FDC /* PurchaseDownloadObserver.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "1"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
Expand All @@ -87,6 +87,12 @@
ReferencedContainer = "container:mas-cli.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "list"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down