@@ -19,6 +19,11 @@ class Tldr {
1919 this . cache = new Cache ( this . config ) ;
2020 }
2121
22+ /**
23+ * Print pages for a given platform..
24+ * @param singleColumn {boolean} A boolean to print one command per line.
25+ * @returns {Promise<void> } A promise when the operation is completed.
26+ */
2227 list ( singleColumn ) {
2328 let platform = platforms . getPreferredPlatformFolder ( this . config ) ;
2429 return index . commandsFor ( platform )
@@ -27,17 +32,33 @@ class Tldr {
2732 } ) ;
2833 }
2934
35+ /**
36+ * Print all pages in the cache.
37+ * @param singleColumn {boolean} A boolean to print one command per line.
38+ * @returns {Promise<void> } A promise when the operation is completed.
39+ */
3040 listAll ( singleColumn ) {
3141 return index . commands ( )
3242 . then ( ( commands ) => {
3343 return this . printPages ( commands , singleColumn ) ;
3444 } ) ;
3545 }
3646
47+ /**
48+ * Print a command page.
49+ * @param commands {string[]} A given command to be printed.
50+ * @param options {object} The options for the render.
51+ * @returns {Promise<void> } A promise when the operation is completed.
52+ */
3753 get ( commands , options ) {
3854 return this . printBestPage ( commands . join ( '-' ) , options ) ;
3955 }
4056
57+ /**
58+ * Print a random page for the current platform.
59+ * @param options {object} The options for the render.
60+ * @returns {Promise<void> } A promise when the operation is completed.
61+ */
4162 random ( options ) {
4263 let platform = platforms . getPreferredPlatformFolder ( this . config ) ;
4364 return index . commandsFor ( platform )
@@ -54,6 +75,10 @@ class Tldr {
5475 } ) ;
5576 }
5677
78+ /**
79+ * Print a random page.
80+ * @returns {Promise<void> } A promise when the opration is completed.
81+ */
5782 randomExample ( ) {
5883 let platform = platforms . getPreferredPlatformFolder ( this . config ) ;
5984 return index . commandsFor ( platform )
@@ -70,6 +95,11 @@ class Tldr {
7095 } ) ;
7196 }
7297
98+ /**
99+ * Print a markdown file.
100+ * @param file {string} The path to the file.
101+ * @returns {Promise<void> } A promise when the operation is completed.
102+ */
73103 render ( file ) {
74104 if ( typeof file !== 'string' ) {
75105 throw new MissingRenderPathError ( ) ;
@@ -83,24 +113,41 @@ class Tldr {
83113 } ) ;
84114 }
85115
116+ /**
117+ * Clear the cache folder.
118+ * @returns {Promise<void> } A promise when the cache is deleted.
119+ */
86120 clearCache ( ) {
87121 return this . cache . clear ( ) . then ( ( ) => {
88122 console . log ( 'Done' ) ;
89123 } ) ;
90124 }
91125
126+ /**
127+ * Update the cache.
128+ * @returns {Promise<any> } A promise with the index.
129+ */
92130 updateCache ( ) {
93131 return spinningPromise ( 'Updating...' , ( ) => {
94132 return this . cache . update ( ) ;
95133 } ) ;
96134 }
97135
136+ /**
137+ * Update the index.
138+ * @returns {Promise<any> } A promise with the index.
139+ */
98140 updateIndex ( ) {
99141 return spinningPromise ( 'Creating index...' , ( ) => {
100142 return search . createIndex ( ) ;
101143 } ) ;
102144 }
103145
146+ /**
147+ * Search some keywords in the index and print the results.
148+ * @param keywords {string[]} The given keywords.
149+ * @returns {Promise<any> } A promise when the operation is completed.
150+ */
104151 search ( keywords ) {
105152 return search . getResults ( keywords . join ( ' ' ) )
106153 . then ( ( results ) => {
@@ -109,6 +156,12 @@ class Tldr {
109156 } ) ;
110157 }
111158
159+ /**
160+ * Print all pages.
161+ * @param pages {string[]} A list of pages to be printed.
162+ * @param singleColumn {boolean} A boolean to print one command per line.
163+ * @returns {Promise<void> } A promise when the operation is completed.
164+ */
112165 printPages ( pages , singleColumn ) {
113166 if ( pages . length === 0 ) {
114167 throw new EmptyCacheError ( ) ;
@@ -121,7 +174,15 @@ class Tldr {
121174 } ) ;
122175 }
123176
124- printBestPage ( command , options = { } ) {
177+ /**
178+ * Print a page from the cache.
179+ *
180+ * If the page is not present, the cache is updated.
181+ * @param command {string} The given command to be printed.
182+ * @param options {object} The options for the render.
183+ * @returns {Promise<void> } A promise when the operation is completed.
184+ */
185+ printBestPage ( command , options = { } ) {
125186 // Trying to get the page from cache first
126187 return this . cache . getPage ( command )
127188 . then ( ( content ) => {
@@ -157,6 +218,10 @@ class Tldr {
157218 } ) ;
158219 }
159220
221+ /**
222+ * Print a warning message if the cache is 30 days old.
223+ * @returns {Promise<void> } A promise when the operation is completed.
224+ */
160225 checkStale ( ) {
161226 return this . cache . lastUpdated ( )
162227 . then ( ( stats ) => {
@@ -166,7 +231,12 @@ class Tldr {
166231 } ) ;
167232 }
168233
169- renderContent ( content , options = { } ) {
234+ /**
235+ * Print the page content.
236+ * @param content {string} The content of a page.
237+ * @param options {object<{markdown: boolean, randomExample: boolean}> } The options for the render.
238+ */
239+ renderContent ( content , options = { } ) {
170240 if ( options . markdown ) {
171241 return console . log ( content ) ;
172242 }
@@ -181,6 +251,12 @@ class Tldr {
181251 }
182252}
183253
254+ /**
255+ * Display a spinner while a task is running.
256+ * @param text {string} The text of the spinner.
257+ * @param factory {Function} A task to be run.
258+ * @returns {Promise } A promise with the result of the task.
259+ */
184260function spinningPromise ( text , factory ) {
185261 const spinner = ora ( ) ;
186262 spinner . start ( text ) ;
0 commit comments