老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

nodejs漸入佳境[11]-yargs獲取用戶輸入高級用法-創新互聯

yargs高級用法,用于輸出幫助信息,縮寫提示等。

瑪多網站制作公司哪家好,找成都創新互聯!從網頁設計、網站建設、微信開發、APP開發、成都響應式網站建設公司等網站項目制作,到程序開發,運營維護。成都創新互聯從2013年創立到現在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選成都創新互聯

app.js:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//打印字符串
const yargs = require('yargs');
const nodes = require('./nodes.js')

const argv = yargs
 .command('add','add a new note',{   //add為命令參數,第二個為說明
   title:{       //--titile
     describe:'Title of note',
     demand:true, //必須要的參數
     alias:'t'  //縮寫 //--t
   },
   body:{
     describe:'Body of note',
     demand:true,
     alias:'b'
   }
 })
 .command('list','List all notes')
 .command('read','Read a note',{
   title:{
     describe:'Title of note',
     demand:true,
     alias:'t'
   }
 })
 .command('remove','Remove a note',{
   title:{
     describe:'Title of note',
     demand:true,
     alias:'t'
   }
 })
 .help()
 .argv;
var command = process.argv[2];

if(command==='add'){
  var note = nodes.addNote(argv.title,argv.body);
 if(note){
   console.log('add success');
   console.log(`title:${note.title}`);
   console.log(`body:${note.body}`);
 }
}else if(command === 'list'){
   var allnotes =  nodes.getAll();
   allnotes.forEach((note)=>{  console.log(note)});
}else if(command =='read'){
 var note = nodes.getNote(argv.title);
 if(note){
   console.log('find');
   console.log(`title:${note.title}`);
   console.log(`body:${note.body}`);
 }else{
   console.log('note not found');
 }
}else if(command=='remove'){
 var noteRemoved =  nodes.removeNote(argv.title);
 var message = noteRemoved?'Note was removed':'note not found';
 console.log(message);
}else{
 console.log('command not find');
}

nodes.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
console.log('start nodes.js');
const fs = require('fs');
//從文件中獲取節點
var fetchNode = ()=>{
 try{
   var notesString = fs.readFileSync('notes-data.json');
   return JSON.parse(notesString);
 }catch(e){
   return [];
 }
}
//保存節點到文件
var saveNote = (notes)=>{

 fs.writeFileSync('notes-data.json',JSON.stringify(notes));

}

//增加節點,如果新增返回新增節點。
var addNote = (title,body)=>{
 var notes = fetchNode();
 var note = {
     title,
     body
 };

 //篩選出相同的節點
 var duplicateNotes = notes.filter((note)=>note.title===title);
 //沒有相同的節點
 if(duplicateNotes.length ===0){
   notes.push(note);
   saveNote(notes);
   return note;
 }
}

var getAll = ()=>{
 var notes = fetchNode();
 return notes;
};

var getNote = (title)=>{

 var notes = fetchNode();
 //篩選出相同的節點
 var duplicateNotes = notes.filter((note)=>note.title===title);
 return duplicateNotes[0];
};

var removeNote = (title)=>{
 var notes = fetchNode();
 //篩選出不同的節點
 var duplicateNotes = notes.filter((note)=>note.title!==title);
   saveNote(duplicateNotes);
   return notes.length !==duplicateNotes.length;
};

module.exports = {
   addNote,
   getAll,
   getNote,
   removeNote
};

測試

打開控制臺,在當前目錄下輸入:

1
> node app.js add --help

控制臺返回結果:

1
2
3
4
5
6
7
8
9
app.js add

add a new note

選項:
 --version    顯示版本號                                                 [布爾]
 --help       顯示幫助信息                                               [布爾]
 --title, -t  Title of note                                              [必需]
 --body, -b   Body of note                                               [必需]

輸入:

1
> node app.js  --help

控制臺返回結果:

1
2
3
4
5
6
7
8
9
10
11
app.js [命令]

命令:
 app.js add     add a new note
 app.js list    List all notes
 app.js read    Read a note
 app.js remove  Remove a note

選項:
 --version  顯示版本號                                                   [布爾]
 --help     顯示幫助信息                                                 [布爾]
  • 本文鏈接: https://dreamerjonson.com/2018/11/14/node-11-yargs/

  • 版權聲明: 本博客所有文章除特別聲明外,均采用 CC BY 4.0 CN協議 許可協議。轉載請注明出處!

nodejs漸入佳境[11]-yargs獲取用戶輸入高級用法

創新互聯www.cdcxhl.cn,專業提供香港、美國云服務器,動態BGP最優骨干路由自動選擇,持續穩定高效的網絡助力業務部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統配攻擊溯源,準確進行流量調度,確保服務器高可用性。佳節活動現已開啟,新人活動云服務器買多久送多久。


分享文章:nodejs漸入佳境[11]-yargs獲取用戶輸入高級用法-創新互聯
分享URL:http://www.xueling.net.cn/article/decoip.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 亚洲阿v天堂在线2017 | 久久精品欧美日韩精品 | 隔壁老王国产在线精品 | 精品中文字幕在线2019 | 国产精品无码久久久久久久久久 | 激情黄页| 日韩国产精品久久 | 精品国产三级a在线观看 | 国产精品天堂 | 亚洲VA中文字幕无码毛片 | 曰韩精品一区二区 | 伊人大杳焦在久久综合网 | 老司机伊人| 日韩在线一二三四区第一页 | 成人久久18免费网站麻豆 | 亚洲国产一区精品 | 欧美日韩h | aaa大片在线观看 | 狠狠丁香 | 美女被强遭的免费网站视频 | 污网址在线观看免费入口 | 亚洲欧美国产精品久久久久 | 97视频在线视频 | 91大神一区二区 | 日产精品久久久久久久性色91 | 成人免费公开视频 | 推油少妇久久99久久99久久 | 中文字幕久久一区 | 国产精品网站一区二区三区 | 亚洲图片日本V视频免费 | 黄色免费日本 | 97国产在线播放第一页 | 精品视频一区在线视频 | h片在线免费观看 | 女女女女bbbb毛片免费视频 | 又色又爽美女网站 | 成全高清视频免费观看动漫版 | 日韩免费一级 | 韩国理伦伦片在线观看 | 亚洲国产毛片 | 国产又大又粗又爽的毛片 |